Rockets to face in the direction it‘s going

I've been wondering, is there a feature where you can, like for my example, set the rotation of sprites depending on the direction it is going?

For example :

When i shoot the rocket upwards, it will face upwards.
when the rocket starts to fall downwards due to gravity, the rocket's sprite would also start rotating and face downwards.

Or something to simulate behaviors similar to shuttlecocks in badminton.

 

A:

 

On each step you need to store the position of the object you want to rotate and then compare that to the current position, it would look something like this:

float angle = -CC_RADIANS_TO_DEGREES(atan2f(oldPos.y-myObject.position.y, oldPos.x-myObject.position.x)); 
angle = angle < 0 ? angle + 360 : angle; myObject.rotation = angle - 180.0f;        
 // I minus 180 so that my object is facing the right direction, depending on your objects initial layout y//ou may have to plus or minus a different number.  
oldPos = myObject.position;
 

 

上一篇: How to make enemies follow your hero (seeking missiles)
下一篇: 子弹跟踪算法
912sy.com
博客等级 码龄15年 9粉丝 40原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值