- Home /
How to have my player “ride” along with moving platforms?,How to have my character “ride” along with moving platforms?
I'm new to unity and here am developing a game for htc VIVE, am using steamvr player prefab in my game and there are some moving platforms by using that player can cross from one side to another. The issue is when player steps on the it he is not moving along with the moving platform he literally stands on the same X position and some How I figured it out that its a issue with player collider. Is there any possibile way to achieve this without using any collider/rigidbody. Open to any idea/solution you guys can come up with. Below is the code which i have used to move the player. Any type of information would be truly appreciated.
public GameObject player;
private void OnTriggerEnter(Collider other)
{
if(other.gameobject == player) {
playter.transform.parent = transform;
}
}
private void OnTriggerExit(Collider other)
{
if(other.gameObject == player)
{
playter.transform.parent = null;
}
}
Answer by Optrix · Jul 03, 2019 at 12:16 AM
In a 2D game I'm working on, I check to see if the player object is 'grounded' by firing a ray with Physics.Raycast directly downwards.
If I'm grounded, I store the collider I'm grounded to, and it's current position.
Then, if remain grounded between frames (ie I haven't jumped) and the 'ground' collider moves at all, I move the player by the same amount. Basically, the player copies the movement of the platform.
Note that in VR, this will most likely need you to place an empty 'Base' GameObject that your VR camera rig lives inside. This way you can move the Base object when the platform moves, which will then move the VR camera.
Motion Sickness Warning - Transitioning from being self-propelled to having independent movement like this can make some users feel VR/motion sickness. It might be worth adding some extra visual edges to the platform to make it clear you are riding something.
Actually, I want to know how to set the collider for S$$anonymous$$m VR Player(not camera rig) because if I achieve that then I can easily move the player when it collides with the moving platform.
Your answer
Follow this Question
Related Questions
Why my character moves left when i press right key ? Controls are upside down? 2 Answers
Destory/Collect object to open door 1 Answer
Trigger help! 0 Answers
Stamina, Delay C# Script 1 Answer
Player prefab instantiation 1 Answer