I’m prototyping a skateboarding game so I need the board to continue to travel quite a distance after the force has been applied so I’ve got friction and mass down and using
public float moveSpeed; // forward speed
public float rotateSpeed; // speed when turning
public float jumpSpeed; // force applied to a jump
public Rigidbody boardbody; // call the rigidbody
private bool isGrounded; // raycast to the ground
private bool isNotGrounded; // raycast to the ground
private Quaternion xrotation; // trying to normalize forward
private Quaternion rotCur; // Quat for alignment
void Move()
{
// forward
if (Input.GetButton ("A") && isGrounded)
boardbody.AddForce (transform.forward * moveSpeed);
// slowdown
if (Input.GetButton ("B") && isGrounded)
boardbody.AddForce (-transform.forward * (moveSpeed / 2));
}
to go forward and slowdown which is working nicely. I’ve got a few rotation things to tilt and to properly rotate, for example my rotation >>
void Rotate()
{
if (isGrounded)
{
float rotateAroundX = Input.GetAxis ("LeftStickX") * rotateSpeed;
Quaternion xrotation = Quaternion.Euler (0, rotateAroundX, 0);
boardbody.MoveRotation (boardbody.rotation * xrotation);
}
}
However, after I stop applying forward motion with (“A”) the rotation no longer effects the “forward” or rather I should say if not holding down (“A”) then the board just spins (rotates correctly lol) and continues traveling in whatever direction.
I’d like the board to change its “forward” (I think that verbalizes what I’m aiming for) while continuing to coast or “roll” forward even if I’m not holding down the (“A”)
I started another method to try to maybe normalize the forward or update it I’m not sure what I need to do but his is where I am at
void FixForward() // set apply forward magnitude to new rotation angle
{
if (isGrounded)
{
Vector3 targetForward = xrotation * Vector3.forward;
}
}
because a Quaternion isn’t really a vector right so I tried to define one. I am just not sure how to apply it, when I do something like >boardbody.transform.rotation = targetForward * moveSpeed;< I get a constant force that pushes the board ha ha and it flies off the world.
I’m sure it has to do with the fact that I’m applying forces to transform rather than world space V3, Anyway if you guys have any ideas I really appreciate it!