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

Force on one axis only?

$
0
0
I have a paddle(platform) like in breakout/arkanoid game, and once a ball hits in a specific location(left/right) then I want to have ball move with certain force on X axis. This code is working technically, but what it does is that it just "adds" up to the sum of force, but I want it to apply the new force and not add it up to the old one. This script is attached to the paddle(platform); function OnCollisionEnter(col : Collision) { for (var contact : ContactPoint in col.contacts) { if(contact.thisCollider == collider) { var english = contact.point.x - transform.position.x; contact.otherCollider.rigidbody.AddForce(192f*english,0,0); } } } What happens now is that, if the ball moves at -384 X, and I want it to move at force of 192 X, but it just "adds" the new force, so the outcome is -192 X when I want it to be 192 X. What should I do to have it apply the new force on X, and not change Y and Z?

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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