- Home /
Wall Running with triggers, how to do it?
I'm making a free running/parkour game like mirror's edge and one of the best ways I can think of is making 3 triggers on the player, one on left, one on right, and one on front of the character, my character is a rigidbody btw, I want to add probably one script for each trigger, to call something like this:
function OnTriggerEnter (col : Collider)
{
if ( col.gameObject.tag == "wall")
sendMessage ("WallRunRight")
}
but how do I send a function like this to my main script? and then On my main script I would have like a function o tell what that function does? Or you think it's better this way?
var MainPlayer : gameobject;
var WallRunningRight : boolean = false;
function OnTriggerEnter (col : Collider)
{
if ( col.gameObject.tag == "wall")
WallRunningRight = true
}
and then on function update I would use something like this;
function update ()
{
if (WallRunningRight)
MainPlayer.rigidbody.useGravity = false; // then I'll add some force to decal down over time, but tell me wich way you think it's better or even if none of these would do a good work
}
edit: ok it is kinda working I tried the second one but it's giving me some problems, Idk Why but when I jump during left wallrun it goes more far than if I jump while right wallrun, and when I'm in right wall run and pressing "D" to go against wall it jumps to the left as it should, but if I'm on a left wall run and press A against the wall and then jump I jump to the wall instead and that will let me jump multiple time since I don't go away from the wall. Take a look at my scripts please: http://pastebin.com/hFZ20fmH, it's the main script, right wall run script : http://pastebin.com/njk53BXZ and left wallrun script: http://pastebin.com/QntPxR8A
Answer by MadJohny · Mar 03, 2013 at 03:48 PM
Wow, I'm surprised by myself, I actually did it but if someone can help me in maths like fall from wallrun after a certain time...
edit: Ok I dunno why but when I juump while doing a left wall run I go so much far compared to the right wall run jump, someone please take a look at my scripts: wall run right script: http://pastebin.com/0dxtnR2V wall run left script : http://pastebin.com/aBd9KZFG and the general movement script : http://pastebin.com/zFjCRift
Dude! These 3 sripts are amazing! I've been editing them for the past few days and it works like a charm! You're awesome at coding!