I want to rotate a sprite object towards another. Simple enough if the two objects are on the same layer, however when they are on different layers I run into some issues.
In my case I have an object placed on a GUI layer that should point towards an object on the layer below. Is there special considerations I should take?
You can use the action to rotate a sprite toward another, but before doing this, make sure the positions of the objects are correct :
When objects are on a GUI layer, their position are usually from 0;0 to 800;600 ( or larger depending on the window size ). If you try to rotate them toward an object which is on another layer, the new orientation will be computed thanks to the position of the other object, no matter where the camera of the other layer is.
For example, if you moved the camera of the base layer to the position 5000;5000, so as to follow the hero or another object, then when rotating a GUI object toward a game object, the GUI object orientation will be false.
To make sure the action is working, you have to :
-Change the position of the GUI object to make it relative to the base layer camera.
( For example if your GUI element is positionned at the offset -200;-300 with respect to the center of the screen : Do = Camera.X()-200;= Camera.Y()-300 to the position of GUIobject )
-Then use the rotate toward an object action to change the Gui object angle. At this point, the orientation of the object is correct, but not its position.
-So finally, change again the GUI object position to put it back to its original place ( i.e: Do = Camera.X(“GUIlayer”)-200;= Camera.Y(“GUIlayer”)-300 to the position of GUIobject )
Thanks for your reply
I tried to put all three of these actions in one event, without any condition, which is why I figured you meant. However, the GUI object i moving around, seemingly relative to the object it is rotating towards. Do I need some kind of condition (I would believe this is something that should happen all the time, not only when certain criteria are met).
No conditions should be needed indeed… Can you upload a screenshot of your event ?
The positions used here are just for testing purposes (not sure where to put the object yet), but I don’t see why that should be a problem.
hello im having problems finding the Rotate towards (other object) im doing the tutorial ( wiki.compilgames.net/doku.ph … rtutorial2 ) i have 3 rotate options all under sub dir ANGLE (used the search with word rotate)
rotate toward angle
rotate toward position
none of those have an option to put the player object/sprite…
any help would be nice
The tutorial needs to be updated.
Now, this action has been depreciated (so removed for future games).
Instead, you should use “Rotate toward a position” and set MyObject.X() and MyObject.Y() as position (these expressions returns the X and Y position of MyObject).
by MyObject do you mean the object im wanting the enemy to point at. so for me my turret is called obj_turret and my enemy object is called obj_enemy. so your saying “Rotate toward a position” and set obj_turret.X() and obj_turret.Y() as position ???
This is the text i have found makes it work perfect
Rotate obj_enemy towards obj_turret.X(Centre);obj_turret.Y(Centre) at speed 0deg/second
without (Centre) they were doing a funny spin when close to the tank as i think they were going towards Origin.
This is good( = to game maker or maybe better in time as i get used to it) software so far the tutorials do seriously need an update
Thank you for the help
Yep, when using MyObject.X() and MyObject.Y() alone, it returns the position of the top-left corner of the object, that’s why the direction of the turret is strange when the enemy is close to it. Using MyObject.X(Centre) and MyObject.Y(Centre) returns the position of the object’s center.
i suggest a little change. making the engine give the default center/centre text as Cent as americans spell Centre as Center as both mean the same but i can see this causing some easy mistakes. if cent is used then its ok for both spellings
Just an idea for making it more universal (or Middle)
Centre is correct in french and in english, so there is no need to change.
When you edit an expression using the expression editor, the list of points is shown.
Yes i know Centre is correct in French & British English. But look at how the americans do it Centre (British spelling) or Center (U.S. spelling). i mean i dont mind about making americans spell words correctly(Centre) but they are a massive target for this engine and Cent Or Middle in the user interface for marking the Centre spot would suit all spelling types.
This should be considered.
I’ve fixed the tutorial (now using the rotate towards a position action)
The tutorials do need a revamp. the video tutorials need a revamp also with a voice over. as i myself use a duel display so i have a tutorial be it text or video on 1 screen and the working engine on the other. A voice on the video tutorial would mean less looking at the video tutorial to see exactly what has been typed .