Hey guys, my title pretty much sums it up. I’ve been stuck on this forever now. I keep breaking and coming back to it but I really want to solve this. Hopefully someone can help me out. I want to consistently rotate my character like a constant forward roll in his direction of movement, just like in sonic the hedgehog. I’ve got his direction of movement working right and his roll movement working but I can’t for the life of me figure out how to have him face his move direction while he rolls forward. Obviously I can’t use transform.LookAt because he’s consistently rolling and his LookAt point will change constantly. Here is what I’ve got… any ideas?
#pragma strict
var rotateSpeed: float = 60;
private var lastPos: Vector3;
function Update(){
var moveDirection = new Vector3(Input.GetAxis("Horizontal"),0,0);
var dist = transform.position - lastPos;
lastPos = transform.position;
var angle = dist.x * rotateSpeed;
if(moveDirection.x > 0){
print("moving right");
transform.Rotate(angle, 0, 0);
}
if(moveDirection.x < 0){
print("moving left");
transform.Rotate(-angle, 0, 0);
}
}