Make a mesh face the camera?
Blitz3D Forums/Blitz3D Beginners Area/Make a mesh face the camera?
| ||
How can I make a mesh rotate towards the cameras position? I looked at something on as3, but when doing it in blitz3d, I use Z instead of y, and I only want it to rotate yaw Instead, the object just spins around when you move help? For c.Obj=Each Obj zDifference# = EntityZ(player) - EntityZ(c\evilcube) xDifference# = EntityX(player) - EntityX(c\evilcube) radiansToDegrees# = 180/Pi RotateEntity(c\evilcube, EntityPitch(c\evilcube),ATan2(zDifference, xDifference) * radiansToDegrees,EntityRoll(c\evilcube)) Next It was based of this: http://as3gametuts.com/2013/06/08/top-down-rpg-shooter-3/ |
| ||
http://blitzbasic.com/b3ddocs/command.php?name=DeltaYaw&ref=3d_cat |
| ||
Aside from that, no built in B3D command uses radians for any purpose (they all accept or return their values in degrees) so that radians-to-degrees conversion will be throwing the result way off. |
| ||
Lots of ways, align to vector, pointentity, deltayaw, |
| ||
Found DeltaYaw to be very buggy, sometimes even get "Memory access violation" But got the other method working! RotateEntity(c\mesh, 0,ATan2(EntityZ(player) - EntityZ(c\mesh), EntityX(player) - EntityX(c\mesh))+90,0) Basically got rid of the "radiansToDegrees# = 180/Pi" thing and made it all in 1 line thanks to Yasha Thanks for the others helping anyway! |
| ||
Hello. You're not supposed to use it with RotateEntity, which only admits absolute rotation values. It'll look like it's missing the target. DeltaYaw returns a relative value, so you use it with TurnEntity like Floyd exemplified in that documentation thread linked previously (it's the last post, at the bottom of that thread). It also shouldn't give a MAV error unless you supply null entities to it. I did just benchmark the two ways (RotateEntity with ATan2 vs TurnEntity with DeltaYaw), and surprisingly using RotateEntity with ATan2 is the faster method. |