hi ive set up a script to mimic pokemons tile by tile movement system this worked fine but i wanted something slightly different imagine temple run on an open plane, dependant on an invisible grid for movement.
so the player should be constantly moving forward, rotation just rotates on the spot and the player carries on going straight
right now im depending on a start point and ending point and lerping from one to the other which isnt as smooth as it maybe could be but im still a noob at unity and scripting. my main issue is the way ive used my vector 3 its constantly adding to the x axis so when i rotate 90’ it looks like im moving to the side because the script doesnt know ive rotated
anything in multi line comments doesnt work correctly but is what ive tried using, (it rotates the player but i dont know how to update the rest to say
if (rotation == 90) { do this }
public int rotateSpeed;
public float speed;
public float increment;
public float distToGround;
public float jumpSpeed;
public Vector3 startPoint;
public Vector3 endPoint;
public bool isMoving;
public bool isGrounded;
public Rigidbody rb;
public CapsuleCollider sonicDroid;
void Start () {
startPoint = transform.position;
endPoint = transform.position;
rotateSpeed = 90;
jumpSpeed = 6.0f;
rb = sonicDroid.GetComponent<Rigidbody>();
rb.AddForce(1, 1, 1);
distToGround = sonicDroid.bounds.extents.y;
}
void Update () {
if(increment <=1 && isMoving == true)
{
increment += speed/10;
}
else
{
isMoving = false;
isGrounded = true;
}
if (isMoving)
transform.position = Vector3.Lerp(startPoint, endPoint, increment);
if (isMoving == false)
{
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
}
//turn left
/**
else if(Input.GetKey("a")&& isMoving == true){
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector3(transform.position.x,transform.position.y,transform.position.z);
transform.Rotate(Vector3(0,90,0));
}
**/
//turn right
/**
else if(Input.GetKey("d")&& isMoving == true){
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector3(transform.position.x,transform.position.y,transform.position.z);
transform.Rotate(Vector3(0,90,0));
}
**/
else if (Input.GetKeyDown("space")&& isGrounded == true)
{
rb.velocity += Vector3.up * jumpSpeed;
isMoving = false;
isGrounded = false;
}
}
}
it also wont jump? which is strange as i think my code i okay?
and and all suggestions welcome