- Home /
What's wrong with this script?
I have this script, attached to a "platform" When the player touches it, he must get an upward force, But whe the player goes into the trigger, nothing happens. Why?
var theplayer : Rigidbody;
function OnTriggerEnter (other : Collider) {
theplayer.AddForce(0, 100, 0);
}
Answer by bompi88 · Dec 12, 2012 at 02:24 PM
try to use ForceMode.VelocityChange or ForceMode.Impulse.
theplayer.AddForce(0, 10, 0, ForceMode.VelocityChange);
Have you set the masses correctly? It should be real-life values
actually, that should not affect the code i gave you, sorry. That code is mass-independent.
It's no other forces acting on this rigid body at that time? $$anonymous$$aybe you have another force equal to the one you are adding, but it's facing in the exact opposite direction?
Only the character Controller, but I don't think it matters, because I tried with rigidbody.AddForce(0, 10000000, 0) !!!
$$anonymous$$abey because I try to give force to another object, and not the platform itself?
Answer by Statement · Dec 12, 2012 at 02:13 PM
Do you get any errors in the console? Check if the code actually executes by adding a Debug.Log("Adding force to player"); just before you add force.
If you get no errors and you get your message in the console, maybe your player is kinematic? (In such case forces won't affect it at all)
The code executes, and the rigidbody is not set to kinematic
Answer by Loius · Dec 12, 2012 at 05:36 PM
Character Controller overrides physics behaviour. You can't AddForce to it. You have to use a plain old Rigidbody if you want to add forces.
Your answer
Follow this Question
Related Questions
Jump off the edge of the object 1 Answer
Making a player jump, getting random results 2 Answers
jump on collision weird behaviour 2 Answers
How do I stop an object from jumping VERY high at first? 1 Answer
Change rigidbody's jumping speed 2 Answers