If its not a physics object you can use this.objectToTeleport.position.copy(this.gameObject.position) - altough keep in mind position in threejs is local position. In Unity it’s world position. So what you can use tho is our helper methods (e.g. getWorldPosition and setWorldPosition)
If it was a physics object (has a rigidbody) you should use the method teleport() on the rigidbody component to not get super extreme forces
regarding “they both failed” - what does happen when you call the method? How do you call it? They both should also be working (well except the fact that position is local space so that might just be it here)
I assumed it might be the local position shtick. It behaved like it.
On the first try, I was teleported backwards, so I guess it was because the TP point is on z=-6 on local.
Does .teleport() on rigidbody rotate? If not, are there any best practices there?
Right, teleport only has position arguments right now. Good point. But you can just call resetVelocities on the rigidbody as well and then use the setWorldPosition and setWorldRotation methods
I figured it might be beacuse I am trying to rotate a RigidBody, but when I do this.objectToTeleport?.gameObject.setWorldRotation I get an error that GameObject type doesnt have setWorldRotation function
The threejs class doesnt, yes. You can use our utility method (import { setWorldRotation } from "@needle-tools/engine" or use the util method on components (this.setWorldRotation not this.gameObject.setWorldRotation) - that being said I think we can patch it (add the method) to the threejs objects as well (we already add some other things there anyways
import { Behaviour, Rigidbody, getWorldPosition, getWorldRotation, serializable, setWorldRotation } from "@needle-tools/engine"
import { Object3D } from "three";
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);
this.objectToTeleport?.gameObject.setWorldRotation(rotation.x, rotation.y, rotation.z); // ERROR : Property 'setWorldRotation' does not exist on type 'GameObject'.ts(2339)
}
}```
*by user 198447544408342528*