how do you constrain rotation of actor to moving actor???
i have an actor (gun) that need to rotate between 0-180 degree. The problem is this actor have to rotate when another object (target) moving all the time.
i need the gun to rotate, the rotation to follow target that are moving automatically
at this point i got the gun to follow target but only one time but not all the time.
thanks for help.
i need the gun to rotate, the rotation to follow target that are moving automatically
at this point i got the gun to follow target but only one time but not all the time.
thanks for help.
Best Answers
-
JohnPapiomitis Posts: 6,256
Make 2 real attributes called targetX and targetY
In the target actor constrain targetX to self.position.x and constrain targetY to self.position.y
In your gun Constrain rotation to vectorToAngle(self.position.x-targetX,self.position.y-targetY)
That will have it always rotate to face the target.
If you want it to always rotate to face the target, but limit the rotation between 0-180 degrees then constrain the guns self rotation to
max(0,min(180,vectorToAngle(self.position.x - targetX , self.position.y - targetY )))
Also make sure that the gun image is facing right.
Hope that helps -
tatiang Posts: 11,949
vectorToAngle determines an angle based on two points' x and y positions. From the GameSalad Cookbook:
vectorToAngle (Function)
Finds the angle relative to the origin 0,0, given an X and Y coordinate. For instance, vectorToAngle(100,200)=63.435. You can also find the angle relative to an offset - for instance, vectorToAngle(x-x',y-y'). VectorToAngle(100-200,150-250) will find the angle between the points 100,150 and 200,250, or -135 degrees.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
-
tatiang Posts: 11,949
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
i got simple question.....what is vectorToAngle do exactly?