Rotation change Translation axis, how to compensate it?

Hello !

I’m working on a game but I have a problem : when I rotate an object the Vector3 of his position follow its rotation, so it’s usefull to rotate player and keep its “forward” direction.
But I want to keep my world axis when I change the rotation of this object. There is a function for it ?

For example :
My camera doesn’t move
I have a chair, with the z axis like this :arrow_down: and the x axis like this :arrow_right: . If I do a translation with 90° (with this.gameobject.rotate()) now the z axis is like this :arrow_right: and my x like this :arrow_up: .
But I want to keep the initial transformation axis, how could I do that ?

Original Post on Discord

by user 224464722878005248

There is a theejs method for it yes

https://threejs.org/docs/#api/en/core/Object3D.rotateOnWorldAxis

Is that what you mean?

I tried it but, for example this cube :

by user 224464722878005248

by user 224464722878005248

With my arrows, I can rotate on the Y axis

by user 224464722878005248

But with rotateY or this.gameObject.rotation.y or this.gameObject.rotateOnWorldAxis( new Vector3(0,1,0), -1 *this.context.time.deltaTime * this.speed )

by user 224464722878005248

I get the same result, which is :

by user 224464722878005248

by user 224464722878005248

And I would like this :

by user 224464722878005248

by user 224464722878005248

Is there a way to always translate objects along the same static axis (like the world’s) no matter how they rotate? Without using a parent?

by user 224464722878005248

Like this :

 transform.Translate(new Vector3 (0, -fallingSpeed, 0) * Time.deltaTime ,Space.World);

In unity ?

by user 224464722878005248

That’s exactly what rotateOnWorldAxis does

import { Behaviour } from "@needle-tools/engine";
import { Vector3 } from "three";


export class Rotate extends Behaviour
{
    update(): void {
        this.gameObject.rotateOnWorldAxis(new Vector3(0, 1, 0), 0.01);
    }
}

20221216-143506_Made_with_Needle_-_Google_Chrome.mp4

So it doesn’t affect the x y or z translation ? It keeps the same direction ?

by user 224464722878005248

Because it doesn’t work like this for me :

update() {
            // On avance
            if (this.context.input.isKeyPressed("q")) {
                this.gameObject.translateX(-1 *this.context.time.deltaTime * this.speed)
            }
            // On recule
            if (this.context.input.isKeyPressed("d")) {
                this.gameObject.translateX(this.context.time.deltaTime * this.speed)
            }  
            // On tourne à gauche
            if (this.context.input.isKeyPressed("z")) {
                this.gameObject.translateZ(this.context.time.deltaTime * this.speed)
            }
            // On tourne à droite
            if (this.context.input.isKeyPressed("s")) {
                this.gameObject.translateZ(-1 *this.context.time.deltaTime * this.speed)
            } 

            if (this.context.input.isKeyPressed("ArrowRight")) {

                this.gameObject.rotateOnWorldAxis( new Vector3(0,1,0), 1 *this.context.time.deltaTime * this.speed )

            }
            if (this.context.input.isKeyPressed("ArrowLeft")) {
                this.gameObject.rotateOnWorldAxis( new Vector3(0,1,0), -1 *this.context.time.deltaTime * this.speed )

            }  

        
    }

by user 224464722878005248