Best practice to teleport an object

wouldnt it rotate the TeleportPoint instead of the objectToTeleport (the player)?

by user 198447544408342528

Updated the reply :slightly_smiling_face: forgot to pass in the object. And you can pass in the whole vector

I will point out that since objectToTeleport is marked with ‘?’, I had to add ‘!’ and also since RigidBody isn’t isObject3D, I had to pass in .gameObject. Result:

        setWorldRotation(this.objectToTeleport!.gameObject, rotation);

by user 198447544408342528

Will try it RN and update :slightly_smiling_face:

by user 198447544408342528

Ah ok sorry wasnt paying attention :slightly_smiling_face:

I think easy access on the gameObject to worldpos etc itself would be very useful so I’ll look into adding this now (and being able to set it)

Not sure why threejs doesnt make this easier ^^

I tried what we got to and it still did not work.
Would love any other ideas :jigsaw:

by user 198447544408342528

One second - will repro

this is the final code for your reproduction:

import { Behaviour, Rigidbody, getWorldPosition, getWorldRotation, serializable, setWorldRotation } from "@needle-tools/engine"

export class TeleportPoint extends Behaviour {

    /** The object to move on teleport */
    @serializable(Rigidbody) objectToTeleport?: Rigidbody;

    public teleport(){
        // teleport
        this.objectToTeleport?.teleport(getWorldPosition(this.gameObject));

        // rotate
        let rotation = getWorldRotation(this.gameObject);
        setWorldRotation(this.objectToTeleport!.gameObject, rotation);
    }
    
}```

*by user 198447544408342528*

Waiting for your update! Thank you!

by user 198447544408342528

import { Behaviour, GameObject, Rigidbody, getWorldPosition, getWorldRotation, serializable, setWorldRotation } from "@needle-tools/engine"

export class TeleportPoint extends Behaviour {

    @serializable(GameObject)
    target!: GameObject;

    /** The object to move on teleport */
    @serializable(Rigidbody) objectToTeleport?: Rigidbody;


    private _start!: GameObject;

    start() {
        this._start = this.objectToTeleport!.gameObject.parent as GameObject;

        let i = 0;
        setInterval(() => {
            i++;
            let target = i % 2 == 0 ? this.target : this._start;

            // teleport
            this.objectToTeleport?.teleport(getWorldPosition(target), false);

            // rotate
            let rotation = getWorldRotation(target);
            setWorldRotation(this.objectToTeleport!.gameObject, rotation)

        }, 1000)
    }

}

sorry teleport has a second argument which is “false” by default and assumes local space

20231118-183141_Fdsfd_-_Google_Chrome-logo.mp4

that’s what the script does ^^

The next version will make this possible :slightly_smiling_face:

image.png

It looks like it rotates for you but it won’t for me. What am I missing? :sweat_smile:

by user 198447544408342528

Good question ^^

maybe I should draw a line to point to where I am trying to rotate my character or somthing, the rotation does not work for me at all

by user 198447544408342528