Question by
MarkusKarlsson · Jun 18, 2016 at 05:50 AM ·
spacerotatearoundorbitrotate-aroundspacegame
How to stop orbiting movement and keep going straight at converging speed
So, the player is rotating around a planet (Sphere) and when click or touch event is detected player starts smoothly moving away from the planet. This I have working with the following code:
transform.RotateAround( centerPos, direction, speed * Time.deltaTime );
var newPos = (transform.position - centerPos).normalized * distance + centerPos;
transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime);
What I'm trying to achieve is "exiting the orbiting movement" and start going straight ahead with the same speed as with the orbiting movement. Can't really explain this in English very well so I made an image to demonstrate what I'm trying to do. The main point is that the player keeps the same speed after detaching from the orbital movement.
So, the red line shows what I'm trying to do. Oh and the player has kinematic rigidbody and sphere collider set to trigger. Planet has just sphere collider NOT set to trigger.
unityquestion.png
(11.4 kB)
Comment