360 image rotation with joystick
LordTarantor
Member, PRO Posts: 890
Hello everybody:
I am using the codemonkey's joystick but I dont know how to make the player change images if he is north or south, left or right. Can somebody help me with this?
I used before and I was able to change image if it was moving right or left but it is not working the same way if I add up or down.
I am using the codemonkey's joystick but I dont know how to make the player change images if he is north or south, left or right. Can somebody help me with this?
I used before and I was able to change image if it was moving right or left but it is not working the same way if I add up or down.
Comments
For example, if the angle is between 45 and 135, then you can use images facing up.
If the angle is between 135 and 225, the image faces left. etc...
if game.angle is -90 change image to (your new image) for exact down
the joystick is tricky because the number is always changing i use equal or less/greater than with some numbers
use a debug text game.angle to watch the angle number change in real time.
It will help you pick the numbers you want for positions of joystick
What I was doing is that if game.stick1grabbed is true
Rule:
Attribute self.MotionLinear velocityX is >or= to vectorto angle 131,225 for right and so on for the rest.
But its not working. Can you tell me what I am doing wrong?
Thanks
It is a function that takes an X and Y coordinate and gives the angle that it creates between 0 degrees and the line it makes from that point to the origin(0,0).
So if you want to find the angle using 2 coordinates you would use vectorToAngle(x1-x2,y1-y2).
In this case, you would not use the linear velocity to determine which image to use.
You would need to do something like
Rule: If ALL
45< vectorToAngle(x1-x2,y1-y2)
135>vectorToAngle(x1-x2,y1-y2)
since you are always using vectorToAngle(x1-x2,y1-y2) you may want to use an attribute that is constrained to that value.
How do I put the 45 or 135 in the rule?
What would be the numbers to use in the x1-x2,y1-y2?
Sorry again.
So your rule would only need
If attribute game.Angle >45
AND attribute game.Angle < 135
x1,y1 and x2,y2 are the coordinates of the Stick actor and the corresponding Base actor.
http://gamesalad.com/game/play/91997
In the player:
Move:
Direction game.Angle relative to actor Move Type: additive
speed: 70*game.DistanceFrom Center/game.BaseRadius
Rule-(Direction)
Whee all
attribute game.stickgrabbed is true
Rule
when all
attribute: game.Angle>131
attribute: game.Angle<225
Animate (right pics)
Otherwise:
Rule
when all
attribute: game.Angle>226
attribute: game.Angle<315
Animate (down pics)
Rule
when all
attribute: game.Angle>316
attribute: game.Angle<45
Animate (left pics)
Rule
when all
attribute: game.Angle>46
attribute: game.Angle<130
Animate (up pics)
So that is what I am doing. The up its ok, If I go left it shows me the animation of the right and if I go down or right, no animation.
Thanks for your patience CodeMonkey.