- Home /
How to get an object's relative position to another.
What I am trying to do is, I want to make it so I can only jump if I am within 1 unit of the walls. How would I do that? How would I count how far player is relative to wall?
Answer by yathishgk · Dec 18, 2014 at 06:55 AM
float distance = Vector3.Distance(a.position, b.position) where a and b are transforms of the player and the wall
Answer by dusty909 · Dec 18, 2014 at 07:30 AM
One way I can think of to do this is to make a trigger collider component on your player model that extends beyond the player for 1 unit. When within 1 unit of the walls, this trigger would activate and you can use this as a check before allowing the player to jump. You can tag the walls and check against that too to make sure it's a wall that triggered the collider if there are other objects in your scene that you don't want the player to be able to jump over.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Increase Jump Through Mouse Clicks? 1 Answer
Help with college assignment -2 Answers
Random.Range produces 2 numbers for me? 1 Answer
Is it possible to position a GameObject as relative to a GUI? 2 Answers