#Player doesnt teleport
1 messages · Page 1 of 1 (latest)
#faq_unity message
i have a rigidbody on my player, but it doesnt work
can you explain it in a more noob terms?
im having a bit of trouble understanding
The collisions and trigger methods will only be called
On objects that are in a Collision or trigger of course and have a rigidbody on them
You need only one rigidbody for Collision
But for receiving the call back in an objects you would need a rigidbody on that object
so i need to have a rb on my player?
So as you said you have a rigibody on the player if you try the same thing in a script on the player
It will work as the OnTriggerEnter will actually be called
On the object with the script.
Whatever object this is.
The OnTriggerEnter isn't even being called
As it doesn't have a Rigibody on it
Oh is your player's rigidbody a kinematic one?
If not then use MovePosition or set it as kinematic before moving it around.
i messed up and turns out i dont have a rigidbody on my player, but every other trigger worked exept for this, so i tought i did

so i need to have a rb on both objects or just one?
this trigger should teleport my player to the same pos in all axis, exept for z axis, which would need to be + 15
Well you can simply have on the player
- Then check for Trigger
- use TryGetComponent to access the teleport script
- If found then simply call a method in the script passing in the player itself
Or have 2 rigidbodies
will rb mess with the character controller?
i tried both having a rigidbody, it doesnt work
Yes
Well you can have a kinematic rigidbody
As you are checking for just triggers shouldn't matter
everything seemed fine when i put it on
As kinematic rigidbodies pass through colliders
"It's not working" is not helpful
In order for a question to be answered, it must specify what exactly is wrong. Stating simply that "it doesn't work" is not sufficient.
Source: https://idownvotedbecau.se/itsnotworking
Please elaborate on your question by including all relevant details. What do you think is the problem? Have you tried to fix it? If you have, why didn't that work?
if i have rb on trigger, it spams the debug.log
Also you do realise that your code will teleport the player every time it enters the trigger
You don't have any checks for knowing if it's the correct object or not.
Ok and what happens when it enters?
i previously had it check if the object entering the trigger was tagged by "player", but that didnt do anything either
no errors
only a spam of debug.log
literally every other trigger works, for example, i enter a trigger and i make an enemy move from one side to another, that works perfectly
item pick up triggers work perfectly too
but this just doesnt
So this is the player and could you also send the other obj
Any layer overrides?
As this is the object set as trigger
Try adding a rigidbody to this instead
i have not used any layers
i did that, but it just kept spamming debug.log, but nothing happening when a player goes through
Well the player isn't set as kinematic so it wouldn't move as expected
just added the rb to trigger and set player rb to kinematic and nothing
just debug.log
ill give movePosition a try
is there any other way of doing this without movePosition?
that actually works

it teleports a cube, but not the player
Well can be the player movement depends on how you are moving it
Look into it.
Not quite; Which object the Rigidbody is on doesn't really matter for collision/trigger messages. There just needs to be one involved in the first place.
Using a CharacterController and a Rigidbody in tandem will not work. You need to decide on one or the other.
Also, character controllers will override their object's position. If you want to move the object by other means than the CC, you need to disable it, move the object, and re-enable it.
Oops, meant to reply to this screenshot in my above message.
oh shit, thanks, ill try to do that, when im back on the project
The error is from your code
What you wrote is player.transform = player.transform
You will need to create a new Transform variable for the destination of the player
Where'd you take that from?
OP has shared 1 piece of code. Nowhere in that code do they ever re-assign the player's transform (not to mention that this wouldn't even be possible).
But even if you mean that they wrote player.transform.position = player.transform.position, you would be wrong. OP did add 15f to the player's z position. Therefor, there would be an effect from just the code itself.
Although player.position += Vector3.forward * 15f; may have been a prettier way of writing it. 
Yes you are right i'm very sorry
I did not see it 😅
It was only seeing player eveeywhere till i was no more paying attention on the rest
vector3.forward changes the z axis only?
Yes.
Vector3.right is always 1 0 0
Vector3.up is always 0 1 0
Vector3.forward is always 0 0 1
The same with -1 instead of 1 for .left, .down and .back.
does transform have that too?
cause i used in one script transform.forward, but tried using also transform.right and it didnt work
only transform forward worked
Transform as forward, right and up. Those behave different from the Vector3 ones, as the former always point in directions *relative to the Transform's rotation.
So if you have a rotation of 90 0 0 and use transform.forward, you'd get a vector facing down.
how would i go about making a character controller be disabled and enabled the milisecond im teleported
and also will it affect the moving?
like for example, im moving and i disable it, enable it back and if im still holding W, the entire time, will i still move?
you just cs myCharacterController.enabled = false; transform.position += Vector3.forward * 15f; myCharacterController.enabled = true;
The controller won't respond to move calls when disabled.
Whether it will keep moving though, depends largely on your input code. After all, the controller would effectively not be disabled for long enough to notice any stopping.