Quantcast
Channel: Answers by "Matt-Downey"
Viewing all articles
Browse latest Browse all 90

Answer by Matt-Downey

$
0
0
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.

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>