- Home /
2D Physics based rotation looses precision after hours
Hi all,
im trying to develop hill climb racing clone, simple 2d noisy terrain with vehicles and events on it.
While implementing my version of "floating origin" technique for vehicles and terrain, everything seems to be okay, but i noticed one weird behaviour of rotation on my vehicles' wheels.
Test scenario is: I have vehicle. 2D physics, sprites, wheeljoints, circle colliders, classic setup. That is travelling great distances (resetting to 0,0,0 coords after configured distance is reached, maximal limit is 10km) but i do not reset rotation of wheels on that vehicle, because i think it is not necessary.
When game is started, everything works perfectly. But after night of testing while i was sleeping, 2700 kilometers passed and wheels rotated 1.436.170 times, they looses precision, so when im travelling beyond 20kmh wheels do not rotate, and then they rotate about 40kmh while vehicle is going 21kmh. But, vehicle is accelerated only through torque applied on wheels and there is no other way of setting wheel gameobject parameters. Vehicle can still smoothly accelerate, only visible problem is that graphical rotation does not match physical rotation. No jittering or shaking, only graphical rotation seems to stick to rotation speeds of 0kmh 40kmh 80kmh and so on, but nothing in between, and only after travelling for hours.
I have no idea what can potentially cause this. And im trying to understand what can potentially do this and how to avoid this.
PS: i noticed one more weird behaviour now in hinge joint 2d test scenario: I connecting trailer to vehicle by programatically creating hingejoint2d, when they are close enough. HingeJoint2d has reference angle and i need to use this to subtract from angle limits, so trailer can rotate 60 degrees up and down relative to truck independently of angle in which they connect (i understood that reference angle is angle in time of connection creation)
problem: when trailer rotates 360 degrees before connection (looks like rotation was 0 degrees and is actually 0 degrees after full rotation), connecting causes drastical rotation of lighter truck 360 degrees in opposite direction. Somehow after trailer rotation, angle limits on connection, when reference angle subtracted, are 360 degrees below zero, so 60 degrees up and 60 down becomes something like -300 and -420 degrees.
what i can think of possible solutions: problem a) when resetting position, also set rotation like "transform.rotation = transform.rotation % 360 degrees" problem b) referenceAngle = joint.referenceAngle % (2f * pi)
I think they have something in common. Some variable seems to not resetting after full rotation. Any suggestions please? Thx, Ascaria
Your answer
Follow this Question
Related Questions
OnCollisionEnter2D calls when really no collision 1 Answer
multiple objects on oncollissionstay2d 1 Answer
How do i stop rigidbody2D bounce 1 Answer
Location of RigidBody2D on collision 3 Answers
My character won't collide with walls 2d 0 Answers