News › Forums › RAIN › General Discussion and Troubleshooting › Velocity
Tagged: Velocity NavMesh rigidbody
This topic contains 4 replies, has 2 voices, and was last updated by
Cyrawnis 6 months, 4 weeks ago.
-
AuthorPosts
-
January 10, 2023 at 12:27 pm #39837
Hello everyone,
I’m fairly new to Rain, and I seem to be having trouble returning the velocity of an object’s rigidbody.
What I am trying to do:
- Create a cube as the navigator
- Create Rain Navigation Mesh
- Attach an ai and rigidbody to the cube
- Use the ai to walk along a route set up by waypoints <- This is working properly
- Use the rigidbody on the cube so that I can get the velocity of the cube <- Not working properly. It is always returning zero.
- I need the velocity of the cube so that I can tell what direction it is going on the xz axis. I don’t care what direction it is facing, just the direction it is moving towards North, South, East, West.This will be used to position the second object at the same position as the cube and play animations depending on what direction the cube is moving. The position works, I just can’t get the velocity to work when using rain. It works with a regular navigation mesh with a nav mesh agent, but not a Rain mesh with a rigidbody.
I appreciate the help,
Cyrawnis
-
This topic was modified 7 months ago by
Cyrawnis.
January 10, 2023 at 12:33 pm #39838void Update() { if (rb.velocity.x == 0) { // Play animation } else if (rb.velocity.z > .5f) { // Play animation } else if (rb.velocity.z < -.5f) { // Play animation } else if (rb.velocity.x > .5f) { // Play animation } else if (rb.velocity.x < -.5f) { // Play animation } }-
This reply was modified 7 months ago by
Cyrawnis.
January 12, 2023 at 6:03 pm #39848RAIN doesn’t modify the velocity of the rigid body to move as it goes, it uses direct movement (just sets the position on the object’s transform).
You can get the velocity from the AI though:
public void Update() { // Probably should be in Start instead RAIN.Core.AIRig tRig = GetComponentInChildren<RAIN.Core.AIRig>(); // Depending on when you call this (via Update, or LateUpdate, or wherever) // one of these should be right Vector3 tPriorVelocity = tRig.AI.Kinematic.PriorVelocity; Vector3 tVelocity = tRig.AI.Kinematic.Velocity; // Do stuff }January 13, 2023 at 9:55 pm #39863Thank you very much, this really helped a lot with pointing me in the right direction for my research!
January 13, 2023 at 11:27 pm #39864 -
This topic was modified 7 months ago by
-
AuthorPosts
You must be logged in to reply to this topic.