- Home /
Applying force to character inside trigger
I'm trying to create an area which has a wind which pushes my character backwards, without using a rigidbody (as I've heard this can cause issues). I've been using the answer from a basically identical question found on this site here:
However, the answer was written with C#, and I'm trying to keep all of my code in javascript. I tried converting it, but I've obviously made an error somewhere due my very limited understanding of C#. Heres the script as it stands in my project.
var direction : Vector3; var speed = 2.0; var ctrl : CharacterController; direction = Vector3(0,1,0);
function OnTriggerStay (other : Collider) { ctrl = other.gameObject.GetComponent(CharacterController); if (ctrl) { ctrl.SimpleMove(direction * speed); } }
I may have oversimplified somewhere. As is, my code doesn't work at all. Where am I going wrong?
P.S, sorry for butchering someones much more elegant code XD
$$anonymous$$y problem has turned out to be that my character is restricted from moving in the Z axis. I can't seem to find a way to allow this movement (i'm not even sure where it's restricted). Anyone have any ideas?
Answer by Alienjesus · Apr 09, 2011 at 03:44 PM
The code works fine once I set it to move the character in the x axis. Something is restricting movement in the z axis.
Answer by Persona · Apr 05, 2011 at 05:27 PM
The direction you set will have it going upwards, not backwards. Try applying the force to the Z axis.
direction = Vector3(0, 0, 1)
Yeah, I only tried setting to that because Vector3(0,0,-1) which was what I had before wasn't working.
Your answer
Follow this Question
Related Questions
Enemies movement 1 Answer
My jumping script has errors 1 Answer
Wind that is activated using keypress 0 Answers