Best practice to teleport an object

Maybe useful
image.png

Not sure what’s different for you honestly. Except the local position teleport argument

What I am looking for is transform.forward which is SUPER useful in this position…

    update(): void {
        let rotation = getWorldRotation(this.gameObject);
        Gizmos.DrawLine(this.gameObject.position, rotation.normalize().add(this.gameObject.position));
    }

any idea how to fix it? Haven’t dealt with vector mathematics since the University haha

by user 198447544408342528

I am trying to draw a line from transofrm.position to transform.forward

by user 198447544408342528

I think you just need Gizmos.DrawDirection(<pos>, new Vector3(0,0,1))

I need it towards transform.forward not vector3.forward :slightly_smiling_face:

by user 198447544408342528

Unlike Vector3.forward, Transform.forward moves the GameObject while also considering its rotation.

by user 198447544408342528

new Vector3(0,0,1).applyQuaternion(this.gameObject.worldQuaternion); (just updated with the world data api)

Ah we already also have forward(this.gameObject) that you can import (import { forward } ...). Might also be something useful to add to Object3D

I tried this

    update(): void {
        let endpos = forward(this.gameObject).multiplyScalar(100);
        Gizmos.DrawLine(this.gameObject.position, endpos, Color.NAMES.red);
    }
}```
the lines seem very weird and not at all to the forward direction as in the editor

*by user 198447544408342528*

Is this.gameObject parented to something: use this.gameObject.worldPosition
DrawLine draws a line between two points but you do calculate a forward vector here by calling forward. You need to either add the worldPosition to it again if u use DrawLine or you need to call Gizmos.DrawDirection with the forward (endpos) vector

        let direction = forward(this.gameObject)
        Gizmos.DrawDirection(this.gameObject.worldPosition, direction, Color.NAMES.red);

your gizmos worked :ok_hand:

by user 198447544408342528

unfortunately i couldnt get the rotation to work, ill give it up for now :confused:
The method that worked for you failed for me.

by user 198447544408342528

is there a way to get forward in world space…?

by user 198447544408342528

found it, its getWorldDirection with no second argument.

This did not help either, this code

setWorldRotation(this.cam!, getWorldDirection(this.gameObject))

doesnt work either

by user 198447544408342528

Can you post your full script again? Im out for today but can try to help again tomorrow or monday :wink:

basically

import { Behaviour, Rigidbody, getWorldPosition, serializable } 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
        // TODO. this not working:
        // let rotation = getWorldRotation(this.gameObject);
        // setWorldRotation(this.objectToTeleport!.gameObject, rotation)
    }

}```

*by user 198447544408342528*

Maybe you can try to update and then use these methods?