I was working on Car Wars game so I require to throw the car which crosses circuit boundary.
The following image depicts my point clearly:
Now as per my programming setup, I require to throw my car through force/velocity manually applied and I want to flip the car in the car throwing direction.
I have tried myself about this but didn’t able to get the desired result.
myRigidbody.AddForce(transform.forward * 80f);
Vector3 currentRotation = transform.eulerAngles.normalized;
myRigidbody.angularVelocity = new Vector3(currentRotation.x * Random.Range(10f, 40f), Random.Range(10f, 20f), currentRotation.z * Random.Range(10f, 20f));
Now share your side suggestion regarding this, I want to give force and angular velocity manually based on side of the circuit car diving.
JonPQ
2
you might want to add force in the direction of the edge of the track’s normal vector, not the forward vector of the car… Or at least use the car’s velocity vector perhaps. but track normal might be more consistent ?
the car may be driving sideways or backwards, or at a glancing angle…
That is pretty easy to calculate… if in square center postion of track… force vector is just left or right…
If in the end (curved sections) its just a vector from the center of the circle towards car’s current position. (normalized)
And to make the car rotate… you probably don’t need to alter the angular momentum… just apply your push force at a point above the center of gravity of the car, and you’ll naturally get rotation also…
try using the car’s position or center of mass for target position, plus Vector3.up * heightOffset.
Then apply the force there… using Rigidbody.AddForceAtPosition