- Home /
How to create floating platform?
I have a platform which is positioned above ground and currently has a collider and rigidbody attached. I would like the platform to lower a little when the player jumps on and then raise again when player jumps off.
I would like to be able to control the amount that the platform raises/lowers.
What is the best way of doing this?
I tried using the Spring Joint but got completely lost.
Answer by aldonaletto · Mar 31, 2012 at 05:35 AM
Spring Joint is a good solution (let the Connected Rigidbody field blank, so the spring will be connected to the world). If the player is a CharacterController, use OnControllerColliderHit to apply a force (a pseudo weight) to the platform:
var weight = 10.0; // fake "weight"
function OnControllerColliderHit(hit: ControllerColliderHit){
if (hit.rigidbody){
hit.rigidbody.AddForce(-hit.normal * weight);
}
}
You can tweak the weight and the Spring Joint spring parameter to get the desired effect (freeze rotations and adjust damp to get a better behaviour).
Answer by xofreshxo · May 26, 2017 at 06:04 PM
As of 5.6, I've found that it's better to use an Area Effector place under the platform. I think it's a little easier to control and setup compared to a Spring Joint.
Your answer
Follow this Question
Related Questions
Excluding some physics collisions 3 Answers
My object falls through terrain. 8 Answers
Character Controller Pushes Car With Wheel Colliders? 0 Answers
Player keeps bouncing off the walls 2 Answers
How to setup character Collisions? 2 Answers