- Home /
Player falls through rising platform?
I have a platform in my scene that is made of a cube with a box collier. It rises and falls through out the game. When my player stands on it it collides normally with the surface and can move around as it should,however, when the platform rises, the player falls through the platform. I find this curios as the physics is as it should when the player jumps. How do I fix this so that the player can rise and fall with the platform?
How are you moving the platform? This seems to be a really strange thing, but I've found that if I move something touching another object by directly modifying it's transform.position it will ignore collisions in many cases and move DIRECTLY through things. However when using transform.Translate or when moving an object using physics or directly acting on it's velocity that doesn't ever seem to happen. $$anonymous$$ight be something worth looking into!
thanks for you ideas. I am currently using what is probably not the best method, I am making the trasform.position = Vector3.Lerp(start, end, t) and effecting t in order to move the platform up and down. I tried the translate it doesn't make a difference.
Yeah, I ended up putting a using Character Controller and the Character $$anonymous$$otor script from the Standard Assets. Works like a charm now. Good Luck!
Answer by Zarenityx · Jan 13, 2013 at 09:32 PM
If you are translating or using an animation, it is bound to mess up the physics. What I often do is to make the moving platform a kinematic rigidbody, then animate or alter in code the velocity. This should collide with rigidbody and character-controller players, but players that translate probably won't work. If you are using a rigidbody, try using continuous collision detection to prevent it from slipping through. With this method there is no need to check collision in a script.
Thanks I tried animating it, it seemed to work for a few seconds and then the player just fell through, I also tried altering the velocity but i think I may be doing that wrong as it raises for a sec but then the platform drops. Not sure why perhaps the player is too 'heavy'?
Are you setting the velocity in code? If you are, it is probably doing it once, causing the platform to fly into the air, but then drop again, because there is nothing holding it up. $$anonymous$$y suggestion would be to make an animation animating the rigidbody.velocity, and be sure it looks somewhat like a sine curve- with part of it positive and part of it negative. Set it to loop and it should constantly cause the platform to move up and down.
Note: If you are going to create a script that disables this animation for optimization purposes, be sure to disable the rigidbody too, or it will start falling again.
Thank you so much, I have no idea why it works, but it solves the issue!
Answer by cdrandin · Jan 13, 2013 at 08:39 AM
There are 2 ways I can think of solving this. When your platform is rising match the platform speed and add it to your y velocity to have the player move up as well or you could parent the player to the platform in which the movements are independent of one another. http://docs.unity3d.com/Documentation/ScriptReference/Transform-parent.html
I have tried parenting it, but when i get the collision detection, I fall pass through the object no matter what. I just found out that if the player is moving while the platform rises, then the player will rise with it. I only fall through while the player isn't moving. Is this not odd?
Thanks for your reply, I can try the transform but i have the issue of checking collision....
Answer by robertbu · Jan 13, 2013 at 09:48 PM
Two ideas: perhaps your character is going to sleep, or the relative difference in speed is great enough that your character passes through the platform before the collision registers. My bet is sleep. You can test both by going to Edit/Project Settings/Physics. You can set the sleep velocity to 0 to test for sleep. You can up the Solver Iteration Count to test for velocity issues. Note sleep velocity can be set by script on an object by object basis, so you don't have to set it to 0 for your entire project.
thank you I tried both of these but neither produced anything that pointed to a solution but its very helpful for future reference. Thanks again.
Answer by gkamgul · Oct 28, 2017 at 03:41 PM
I assume that your platform adding force to player while going up and player lost it's balance.try to constrain rotation.
Your answer
Follow this Question
Related Questions
RigidBody2D Movement Stuttering 3 Answers
Why are these object passing through each other? 1 Answer
Non slippery movement 1 Answer
Update speed and physics makes my rigidbody jiggle 2 Answers
Move armature rigidbody character 2 Answers