Help, please
I don’t know how to do that
Hi @thebosser24,
Check the following example on how a body is being teleported once it reaches a certain point in space:
https://developer.playcanvas.com/en/tutorials/Using-forces-on-rigid-bodies/
does this work with characters
Yup, it doesn’t matter what kind of body it is.
does it work like, If i step on a rectangle or something it will teleport me somewhere else?
Sir?
and where do i put the scripts
Hello @thebosser24
You put it in your own script. Example: I want first person movement script. I will create a new one and say like ‘firstPersonMovement’
If the script is correct then it will work. If it is wrong it won’t.
But also you need to put the main scene there, so if you lets say want to teleport to a new level and it’s called new level, then you got to put in the rectangle the teleport script then say new level.
Avoid posting short messages @thebosser24. If you tell a little bit more about what you are trying to achieve and how your game is set up, it’s easier to help you.
i want my character to go to a different room when they step on the rectangle
for cursed life a great jumpscare would be, you surprise teleport to a room there is a jumpscare, thats what im gonna do, Right now im having a tutorial(Room 1) then the game(room 2)
First create a new entity with the name “TeleportPoint”. Set this entity on the right place in room two. Then create a new script for the rectangle and give it the name “Teleport”. Replace the code with the code below. Your rectangle and player need also a collider and a rigidbody. If you are done you can check the result. I have not tested this, so let me know the result.
var Teleport = pc.createScript('teleport');
// initialize code called once per entity
Teleport.prototype.initialize = function () {
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
this.teleportPoint = this.app.root.findByName('TeleportPoint');
};
Teleport.prototype.onCollisionStart = function (result) {
if (result.other.rigidbody) {
result.other.rigidbody.teleport(this.teleportPoint.getPosition());
}
};
do u put this on room 2 also?
I THINK i figured it out
Are you trying to make a game similar to mine?
No, this is meaning its wrong. Can you please give me a link to editor so I can be of much assistance.
did u find anyting?
var Teleport = pc.createScript('teleport');
// initialize code called once per entity
Teleport.prototype.initialize = function () {};
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
this.teleportPoint = this.app.root.findByName('TeleportPoint');
Teleport.prototype.onCollisionStart = function (result) {
if (result.other.rigidbody) {
result.other.rigidbody.teleport(this.teleportPoint.getPosition());
}
};
This should help!