Quantcast
Channel: Questions in topic: "curved path"
Viewing all articles
Browse latest Browse all 116

[Question] Move object along curved path toward mouse in 2D, C#

$
0
0
How can I move an object along a curved path toward the mouse position programmatically? I want the boomerang to travel a curved path as its y position decreases, and moves towards the mouse. In this case the mouse controls a Kinematic Rigidbody 2D game object, that is constrained to movement along the x axis, like a paddle in breakout or pong. Here's an illustration of what I'm looking for: ![alt text][1] Here's the code I'm using now: private Vector3 previousBoomerangVector; void Update () { // if boomerang y is decreasing if (previousBoomerangVector.y > this.transform.position.y) { // move boomerang x towards the mouse x position Vector3 moveTowardsMouse = Vector3.MoveTowards(transform.position, Input.mousePosition, 10f * Time.deltaTime); this.transform.position = new Vector3(moveTowardsMouse.x, this.transform.position.y); } previousBoomerangVector = this.transform.position; } [1]: /storage/temp/66626-curved-path.png

Viewing all articles
Browse latest Browse all 116

Latest Images

Trending Articles



Latest Images

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