- Home /
 
               Question by 
               EntityJTLA · Jun 18, 2013 at 12:40 PM · 
                rotationmovement  
              
 
              Character Movement Issues
I am attempting to create a game with the old "Double Dragon" style movement. I have basic movement and jumping mostly set. The issue that is giving me the most grief is getting my character to turn around when moving backwards. Here is my code so far:
 function Update () {
 var horiz : float = Input.GetAxis("Horizontal")* Time.deltaTime * 8;
 var vert : float = Input.GetAxis("Vertical")* Time.deltaTime * 5;
 transform.Translate(Vector3(-vert,0,0));
 transform.Translate(Vector3(0,0,horiz));  
 if(Input.GetKeyDown(KeyCode.Space) && IsGrounded()){
 rigidbody.velocity.y = jumpSpeed; 
 }
 }
 var distToGround: float;
 var jumpSpeed: float = 8;
 function Start(){
   distToGround = collider.bounds.extents.y;
 }
 function IsGrounded(): boolean {
   return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
 }
Nothing that I've tried so far has worked, and this is my first experience with coding, so do assume that I'm an Idiot with this. Thank You.
               Comment
              
 
               
              Answer by EntityJTLA · Jun 25, 2013 at 06:37 AM
Well, I was able to solve it in a weird roundabout way, but it works as long as I don't want to jump anymore.
 var xrestop : float = -120;
 var xresbot : float = 60;    
 function Update () {     
  var stopPlayer = Camera.main.transform.position.z; 
  var right : float = Input.GetAxis("Right");
  var left : float = Input.GetAxis("Left");
  var vert : float = Input.GetAxis("Vertical");                     
  if(transform.eulerAngles == Vector3(0,0,0)){             
      transform.Translate(Vector3(-vert,0,0));
      transform.Translate(Vector3(0,0,right));
      transform.position.x = Mathf.Clamp(transform.position.x, xrestop, xresbot);
      transform.position.z = Mathf.Clamp(transform.position.z, stopPlayer - 200, 10000);
      }
  else{(transform.eulerAngles == Vector3(0,180,0));
      transform.Translate(Vector3(vert,0,0));
      transform.Translate(Vector3(0,0,-left));
      transform.position.x = Mathf.Clamp(transform.position.x, xrestop, xresbot);
      transform.position.z = Mathf.Clamp(transform.position.z, stopPlayer - 200, 10000);
      }
      
  
  if(Input.GetButtonDown("Left")){
  
  transform.eulerAngles = Vector3(0,180,0);
  }
 
 if(Input.GetButtonDown("Right")){
  transform.eulerAngles = Vector3(0,0,0);
 }
 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                