Quantcast
Channel: Questions in topic: "contact"
Viewing all articles
Browse latest Browse all 75

Wrong ContactPoint position when modifying velocity

$
0
0
I'm working on a game where we have spaceships, and they can behave in two different ways when it comes to applying forces. **Space:** We apply a force in the local forward direction. It pushes the ship. But if we turn, it gives this gliding effect. `rigidbody.AddRelativeForce(0, 0, force, ForceMode.Acceleration);` **Plane:** Simplified. When we turn, our speed is kept in the forward direction. `Vector3 dir = rigidbody.rotation.eulerAngles;` `rigidbody.velocity = dir * rigidbody.velocity.magnitude;` `rigidbody.AddRelativeForce(0, 0, force, ForceMode.Acceleration);` Both of these snippets are taken from `FixedUpdate()`. Now, my problem is that while in Space mode everything works as expected, in Plane mode my collisions seem to be located at the wrong location. `void OnCollisionEnter(Collision theCollision) {` `    Debug.Log(theCollision.contacts[0].point);` `}` In Space Mode, I get results such as `(46.1, 0.0, -71.5)`. All my ships are centered at y=0, so this is expected. Now, Plane Mode. I get for a similar collision results like `(-22.6, -158.3, 152.1)` The more the collision happens at an x close to 0, and the more the angle is facing up (towards +z), the more these coordinates get to the expected value. I have spawned spheres at every collision point, and here is what they look like: ![alt text][1] The few spheres that are stuck in the walls are actually at the right place and were obtained through Space physics. The rest are results of different hits in Plane mode. Keep in mind that they all have the same size... Now, here are my thoughts about this. I think that cheating with the velocity the way I am doing it and the way I found in most of the missile/plane/car tutorials I've seen is not the way to go. Manually modifying the velocity vector resets the inertia (I think) and that may explain why my collisions are not logical. I know my physics, just not enough to make my theory work. Having a forward force like I have is good. But for rotations, we also need a centripetal force. Therefore, in addition to the `Transform.Rotate(...)` that I am using (and which I will change to `rigidbody.AddTorque(...)`), I think I need to add a perpendicular force. F = m * v² / r. m is Mass, v is Speed and r is Radius. Speed is simply `rigidbody.velocity.magnitude`. To make it perpendicular I used something like `cForce * Vector3.Cross([forward vector], Vector3.up).normalized`. Simple, no? Well not really. The values I tried for Mass and Radius don't give the expected results at all. I get a perpendicular force when I turn, but it does not really help. I have been looking for Centripetal Force everywhere in the Forum and Answers of Unity, and I haven't found anything. Am I looking too far? Possibly. There. I'm done talking, I've been wrapping my head around this issue for a long while, I don't know if someone recognizes this issue (contact points all over the place) or if you have made a working prototype of something moving with this kind of physics (with collisions). Thank you very much, sorry for the wall of text. Ask if you need more info about my issue. [1]: /storage/temp/21807-spheres.jpg

Viewing all articles
Browse latest Browse all 75

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>