Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Strafe left and right help

Discussion in 'Scripting' started by will_brett, Oct 2, 2014.

  1. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    Hi there,

    Im using the playermove script from the Complete physics platformer kit off the asset store. I am making some modifications to this to allow for more functionality. I want to add strafing left and right which I thought would be easy but I've hit a bit of a wall.

    How do you go about implementing strafing as the player could be rotated any number of ways in the y axis so you cant just do transform.moveto

    The main use for this strafing would be in my players ledge grab state. Where the player is holding onto a ledge and traverses along it. So I guess the player would need to know what angle the edge is at in the y axis so that it can move along it when left or right buttons are pressed.

    Any ideas, tips and or hints?

    Cheers
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
  3. will_brett

    will_brett

    Joined:
    Feb 16, 2013
    Posts:
    208
    My rigidbody is set to kinematic during ledge grab. So I dont think this will work.

    What I have tried is:
    Code (CSharp):
    1. float h = Input.GetAxisRaw ("Horizontal");
    2.                 Vector3 hSpeed = new Vector3(h*traverseSpeed, 0, 0);
    3.                 rigidbody.MovePosition(rigidbody.position + hSpeed * Time.deltaTime);
    But the character doesnt move at all :S
     
  4. Relativ9

    Relativ9

    Joined:
    Jan 27, 2014
    Posts:
    4
    Did you ever find a solution for this, I'm stuck on a similar issue. My rigidbody is kinematic as of now while climbing ledges, (as that's the best way I can find to have it stay on the ledge, if someone has a better way please I'm all ears :D).

    Initially I thought I could use moveposition, or setting the velocity, but moveposition seems to throw at an incredible force no matter what I set the variables to, while setting the velocity doesn't move it at all (which I'm told it should even if it's kinmatic).