Since my last post, I think I've worked out how to make the character rotate in the quickest direction. Once I've scripted it I'll post the code at the first opportunity I get.
Good day to you, sir!
EDIT:
This is what I have. It's nothing special and it's probably not very efficient. All it does is make the tentacle rotate smoothly towards the mouse when I right-click:
Code: ags
I hope that's at least a little bit useful. I'm just irritated that my maths teacher was right, I did use trigonometry after leaving school.
Good day to you, sir!
EDIT:
This is what I have. It's nothing special and it's probably not very efficient. All it does is make the tentacle rotate smoothly towards the mouse when I right-click:
//In repeatedly_execute_always:
if (cTentacle3D.OrientationY>360.0) cTentacle3D.OrientationY=0.0;// Limit the character's orientation to above 0 degrees.
if (cTentacle3D.OrientationY<0.0) cTentacle3D.OrientationY=360.0;// Limit the character's orientation to below 360 degrees.
// in on_mouse_click, after the left-click part.
Ã, else {// right-click, so cycle cursor
SideX=IntToFloat(mouse.x-cTentacle.x);// make a right angled triangle between the mouse and the character
SideY=IntToFloat(mouse.y-cTentacle.y);
SideY=SideY*1.7; // Stretch the triange to account for the angle of the camera (Not sure about this, but it seems to look right)
RotAngle= Maths.ArcTan2 (SideX, SideY);// find out the goal angle of the triangle
goalAngle = Maths.RadiansToDegrees(RotAngle)+360.0; // Make sure the goal angle isn't below 0
if (goalAngle>360.0)goalAngle=goalAngle-360.0; // Make sure the goal angle isn't above 360
startAngle=cTentacle3D.OrientationY;
if (startAngle<goalAngle){ //find out which is the quickest way to rotate
AngleA = goalAngle-startAngle;
AngleB = (360.0 + startAngle) - goalAngle;
if (AngleA>AngleB) {//Rotate Clockwise
while (!(cTentacle3D.OrientationY>goalAngle-1.0 && cTentacle3D.OrientationY<goalAngle+1.0)){
cTentacle3D.OrientationY=cTentacle3D.OrientationY-2.0;
Wait(1);
}
}
else {//Rotate Anti Clockwise
while (!(cTentacle3D.OrientationY>goalAngle-1.0 && cTentacle3D.OrientationY<goalAngle+1.0)){
cTentacle3D.OrientationY=cTentacle3D.OrientationY+2.0;
Wait(1);
}
}
}
else{
AngleA = startAngle-goalAngle;
AngleB = (360.0 + goalAngle) - startAngle;
if (AngleA>AngleB) {//Rotate Clockwise
while (!(cTentacle3D.OrientationY>goalAngle-1.0 && cTentacle3D.OrientationY<goalAngle+1.0)){
cTentacle3D.OrientationY=cTentacle3D.OrientationY+2.0;
Wait(1);
}
}
else {//Rotate Anti Clockwise
while (!(cTentacle3D.OrientationY>goalAngle-1.0 && cTentacle3D.OrientationY<goalAngle+1.0)){
cTentacle3D.OrientationY=cTentacle3D.OrientationY-2.0;
Wait(1);
}
}
}
ProcessClick(mouse.x, mouse.y, eModeLookat);
}
I hope that's at least a little bit useful. I'm just irritated that my maths teacher was right, I did use trigonometry after leaving school.