- Home /
Walking on walls?
I want a game where buildings and things are climbable like the game [prototype], the way it would work is that if youre pressing the Z key you enter free-run mode. Im fairly new to scripting and only know JavaScript, tutorials would be apreciated so I can get it fixed into my head and maybe prevent me from asking more questions than I need to.
-Thanks in advance
I want to do that too... you have to write your own character controller. in a simple way I guess you want when you collide to a wall the forward input key to be translated to the upward input key. $$anonymous$$irror's edge had a much more complicated structure where each of the grip points were behaving differently. Great stuff.
Answer by skovacs1 · Sep 23, 2010 at 09:08 PM
To run up walls isn't bad, but gets trickier depending upon how you implement your running in the first place.
The simple solution is to raycast in the direction you are running and align your animations to the surface if it is within a certain distance (the distance you'll be moving in the current frame for example). If you add inertia or anything like that, you'd want to consider that too.
I recommend looking at the locomotion system for more on aligning animations to a surface.
Raycasting is simple.
var hit : RaycastHit;
if(Physics.raycast(transform.position, moveDirection, hit, amoutToMoveThisFrame) {
//align yourself to hit.normal as up
}
Also, since you know that the normal you're aligned to is not the world up, you can do smart things like balancing the weight against the surface (wall running la Prince of Persia).
You should also take into account collisions and the character's lean if they lean into their running animation.
Answer by aldonaletto · Sep 22, 2013 at 02:46 PM
Take a look at my answer to this question:
http://answers.unity3d.com/questions/155907/basic-movement-walking-on-walls.html
It posts a script that allows a rigidbody character to walk on any surface - it even jumps to a wall if close enough.
Answer by Sejersen · May 03, 2012 at 07:15 AM
Another "easy" way to do this, using Unity's charactercontroller is by using "Slope Limit". It's a build-in function which allows you to change how high a slope your character can walk, run or climb. - I know this isn't exacly like PoP but it's a start, right? :)
Hope this will help :)
Answer by Matt-Downey · Jun 25, 2012 at 12:51 PM
I'm always late in answering questions on Unityanswers, but...
function Pace (normal : Vector3, vect : Vector3)
{
//By dot product/negative inverse, this is orthogonal to the normal
var right : Vector3 = Vector3(normal.y,-normal.x,0); //in world space
var forward : Vector3 = Vector3(0,-normal.z,normal.y); //in world space
right.Normalize();
forward.Normalize();
//the direction the player will move (tangential),
//which is a combination of any two non-parallel vectors on the correct plane
var direction : Vector3;
direction = right*vect.x + forward*vect.z;
direction.Normalize();
return direction;
}
function GetMoveDir (horizontal : float, vertical : float) //The basic user-input function, which calls subsequent f(x)'s
{
moveDir = Vector3(horizontal, 0, vertical);
moveDir.Normalize(); //makes sure the player can't travel @ 1.41x diagonally
}
function FixedUpdate ()
{
GetMoveDir(Input.GetAxis("Horizontal"),Input.GetAxis("Vertical"));
}
The first function takes in the "vect" from "GetMoveDir," all you have to do is insert the "normal" from a raycast.
Should work 100% of the time if I copied the right bit.
Also, I always use Translate(vector, Space.World) or more recently Rigidbody.MovePosition, Translating an object with respect to itself gets annoying during jumps, as you have to recalculate every--single--frame.
This will work on walls and ceilings. It'll work as you expect on walls and floors, but if I'm not mistaken, ceiling controls will be inverted.
I wrote all this myself, so I should know the fine details a little better, but w/e.
Hi, I was wondering how exactly to get this to work. I have tried almost every kind of combination of movement, but nothing seems to work. Could you please tell me what kind of object this has to be attached to?