Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

(2D) Need Object Moving with AddForce to Change Direction

$
0
0
So I need a player object that is under the effects of AddForce to move from one waypoint to the next to make a sharp directional change with no loss of momentum. Is there a way to do this? Right now I have it so the player stops when they reach the next waypoint (because the alternative seems to be that the player flies off the rails completely.) Here is the code I have for an object changing to the next waypoint. Under Update... if (Mathf.Abs (Nodes[Node2].transform.position.y - transform.position.y) < 0.1 && Mathf.Abs (Nodes[Node2].transform.position.x - transform.position.x) < 0.1) { if (Railroad == true){ //Whether or not player is on rails if (IsNearNode == true){ //Is Player inside of the next node if (Node < NodesNumber){ //Is this NOT the last node in sequence Node = Node + 1; //Move to next waypoint //rigidbody2D.velocity = dir; rigidbody2D.velocity = Vector2.zero; //I know this is here IsNearNode = false; //force current waypoint to no longer function for as long as player is in proximity IsAtExit = false; //Definitionally prevents player from accidentally being at exit } else if (Node == NodesNumber){ //If player is at last waypoint in sequence... IsAtExit = true; } } } } else if (Mathf.Abs (Nodes [Node].transform.position.y - transform.position.y) < 0.1 && Mathf.Abs (Nodes [Node].transform.position.x - transform.position.x) < 0.1) { //The same thing as above but for going backwards. if (Railroad == true){ if (Node > 0){ if (IsNearNode == true){ IsNearNode = false; //rigidbody2D.velocity = dir; rigidbody2D.velocity = Vector2.zero; Node = Node - 1; IsAtExit = false; } } else if (Node == 0){ IsAtExit = true; } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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