Rigidbody Velocity in Local Space?
To preface, I am making a 3D linear ship game, where the parent bounding box changes angles and position to move fluidly with the environment while the child Ship object can move within the X and Y local to the parent.
If the Ship within the bounding box collides with any object, I wanted to check to inverse the collision angle to move it further away from the object, however that requires Rigidbodies and Velocities, which I cannot seem to get working in Local Space as they only work in World Space. This is what I had for movement within Local Space prior to trying to implement Rigidbodies, though I know I'll have to change most of, if not all:
float xPos = 0;
float yPos = 0;
//Check input, set vector speed
if (Input.GetKey(KeyCode.W))
{
yPos = yPos + 1;
}
if (Input.GetKey(KeyCode.A))
{
xPos = xPos - 1;
}
if (Input.GetKey(KeyCode.S))
{
yPos = yPos - 1;
}
if (Input.GetKey(KeyCode.D))
{
xPos = xPos + 1;
}
//Set new position
Vector3 newPosition = new Vector3(xPos, yPos, 0);
transform.localPosition += newPosition * Time.deltaTime * speed;
Any help to get Rigidbody Velocities to work in Local Space would be greatly appreciated.
Your answer
Follow this Question
Related Questions
Why does localPosition only work when there is a parent object? 1 Answer
converting local space vector into world space? 1 Answer
Multiple interior collision spaces/pocket collision dimensions. 1 Answer
Global direction (e.g. Vector3.forward, Vector3.right) from Mouse drag 0 Answers
EdgeCollider2D for the same points as LineRenderer has different position 0 Answers