Game Development Community

MaxRotation

by Maarten Visser · in Torque Game Builder · 06/21/2009 (3:26 pm) · 5 replies

Allright, I'm using FaceMouse to have my entity face the mouse constantly, but I want to add a max rotation to it (since it can rotate 360*, I want it to be in between -45* and 45*).. How is such thing achieved?

Currently I'm working with this piece of code:

function Player::getRotation(%this);
{
%val = %this.getRotation();

if %val > 45
%this.setRotation(45);

else if %val < -45
%this.setRotation(-45);
}

Doesn't seem to work though.. Any suggestions?

Thanks in advance,
MaarX

#1
06/21/2009 (5:39 pm)
The code looks like it should work, the one thing I can think of is that you're not calling the function so it isn't checking the current rotation. You can try putting a schedule in your function to see if that fixes it.
#2
06/21/2009 (6:27 pm)
Try not using the else if function, and just the if function.
#3
06/22/2009 (2:45 am)
Apparently, the function is getting called every time I rotate my object (I see this in the script)

It shows a greyish error:

t2dVectorSub() - Invalid number of parameters!
game/gameScripts/player.cs (13) Unable to find object: '' attemption to call function 'setRotation'

And everytime when I rotate the mouse again, it adds more of these exact lines..

Any suggestions?
#4
06/22/2009 (10:47 pm)
Does your player character have the class of 'Player'? When referring to %this in your function that's referring the the 'Player' class, and not the actual name of your player. That's my 2cents at this point, let us know if you still have problems.
#5
06/24/2009 (5:16 am)
It has the Player class, Yes.. I tried putting the code in the behaviour, and all that happens then, is if I go past 45* the player will be stuck at 45* degrees, I can't 'unstuck' it by moving my mouse up again, it just sticks at 45..

I'll have a few more tries at different codes with this..