unity3d - Unity2d vertical movement logical error -
so, code horizontal movement alright , worked perfectly. problem added code vertical movement , keys pretty doing opposite of want accomplish.
my right key makes character go up, key makes character go right etc.
any appreciated.
using unityengine; using system.collections;
public class charactermovement : monobehaviour { public float maxspeed = 10f;
// use initialization void start () { } // update called once per frame void fixedupdate () { float move = input.getaxis ("horizontal"); rigidbody2d.velocity = new vector2 (move * maxspeed, rigidbody2d.velocity.y); float movev = input.getaxis ("vertical"); rigidbody2d.velocity = new vector2 (movev * maxspeed, rigidbody2d.velocity.x); }
y vertical co-ordinate refer in horizontal call. need swap .x , .y around.
edit: sorry rushed answer, need swap x , why, , swap vector parameters, so:
void fixedupdate () { float move = input.getaxis ("vertical"); rigidbody2d.velocity = new vector2 (movev * maxspeed, rigidbody2d.velocity.y); float movev = input.getaxis ("horizontal"); rigidbody2d.velocity = new vector2 (rigidbody2d.velocity.x, move * maxspeed); }
Comments
Post a Comment