object to constantly rotate to face cursor
by josh Nelson · in Torque Game Builder · 06/06/2009 (11:15 pm) · 3 replies
I am working on a game where I want to have an object mounted to another object (a gun arm mounted to a robot torso image) and I wanted to have the gun arm always facing the cursor, which will be the cross-hairs for the gun arm. does anyone know a way to go about doing this?
About the author
#2
%distance = vectordist(%this.getposition(),playership.getposition());
if(%distance < 70 && %distance > 6)
{
%dx = playership.getPositionX()-%this.getPositionX();
%dy = playership.getPositionY()-%this.getPositionY();
%angle = mRadToDeg(maTan(%dy,%dx));
%this.setRotation(%angle+90);
}
It requires some adaptation, but should be helpful. Good luck.
06/07/2009 (10:36 pm)
This might help you a bit. You'll want to change the context of the object words, but I created this code for a top down shooter I created for practice. Just change the playership object to %worldPos when using the method "scenewindow2d::onMouseMove(%this, %modifier, %worldPos)".%distance = vectordist(%this.getposition(),playership.getposition());
if(%distance < 70 && %distance > 6)
{
%dx = playership.getPositionX()-%this.getPositionX();
%dy = playership.getPositionY()-%this.getPositionY();
%angle = mRadToDeg(maTan(%dy,%dx));
%this.setRotation(%angle+90);
}
It requires some adaptation, but should be helpful. Good luck.
#3
06/07/2009 (10:44 pm)
Hmm... That looks almost like my code for my arrow launcher game.
Torque Owner Andreas Ehnbom