Thursday, April 21, 2016

Giving velocity to an object based on rotation

Leave a Comment

I'm using Cocos-Creator, currently there is no physics implemented so I kinda want to create my own. Here I try to move an object based on its rotation:

    properties: {         speed: 200, },  update: function (dt) {     this.node.x += Math.cos(this.node.rotation) * this.speed;     this.node.y += Math.sin(this.node.rotation) * this.speed; }, 

But the problem is that the object is not behaving as intended to, it's moving in random directions.

Update: The code now is:

update: function (dt) {         var vX = Math.cos(this.node.rotation * Math.PI / 180) * this.speed;         var vY = Math.sin(this.node.rotation * Math.PI / 180) * this.speed;         this.node.x += vX * dt;         this.node.y += vY * dt;     }, 

Still the same problem.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment