Game Mechanics Make objects follow the view regardless of view angle

V

Vrok

Guest
Hello there, I'm new to this forum, and I entered here so I can look for answers.

So I'm working on an engine that allows the camera to move and rotate in many angles. I'm trying to make an object where its 'view coordinates' stay constant regardless of view angle, in other words, make the object move along the view angle, while its position 'appear constant' regardless of view angle.

Here's the code I put in:
x = view_xview + 640 - (640 - 64) * cos(degtorad(view_angle))
y = view_yview + 640 - (640 - 64) * cos(degtorad(view_angle))


Here're some images to give an idea what the problem's about:
Runner 2017-07-26 12-41-25-572.jpg
(view_angle = 0)
The black ring represents the object I want to have it to remain in the same 'position' when the view angle changes. Don't mind the arrows; their x and y coordinates remain constant as I have to deal with the black ring first. And yes, the compass to origin angle should have been 'compass to center angle' in the first place.
Runner 2017-07-26 12-41-37-464.jpg
(view_angle = 45)
This is the problem. Whenever the view angle is rotated, the position of the black ring changes, and does not remain on the same 'view coordinates' as the above picture.
Runner 2017-07-26 12-42-00-901.jpg
(view_angle = 180)
Another screenshot of the problem.

Any idea how to fix the problem in the code?
 

Yal

šŸ§ *penguin noises*
GMC Elder
Your view isn't square, so rotating it while keeping the same borders around the following-object will offset it a bit. I'd recommend manually make the view follow the object using lengthdir_x and lengthdir_y to compute the distance the top-left corner (which is what the view rotates around) should be placed from the player.
 
V

Vrok

Guest
Could you not just use the Draw GUI Event to draw the black ring in a fixed position?

Is there a reason that would not meet your requirements?
I also want to apply the code to the arrows too. One of the arrows is programmed to point towards the direction of camera movement, so I wonder how would I make an image's angle rotatable under Draw GUI, if the arrows and the black ring are to be part of Draw GUI.

Your view isn't square, so rotating it while keeping the same borders around the following-object will offset it a bit. I'd recommend manually make the view follow the object using lengthdir_x and lengthdir_y to compute the distance the top-left corner (which is what the view rotates around) should be placed from the player.
But I'm applying this engine to a shoot'em up I'm working on, where the player and aerial enemies remain on the same 'view coordinates' while the camera's rotating. So I had to test the engine on the 'compass', consisting of the black ring and the arrows.

Just how do I implement the lengthdir functions onto the object?
 
so I wonder how would I make an image's angle rotatable under Draw GUI, if the arrows and the black ring are to be part of Draw GUI.
I would just subtract the view angle from the camera direction or whatever angle you are trying to point at and draw that.
 
V

Vrok

Guest
I would just subtract the view angle from the camera direction or whatever angle you are trying to point at and draw that.
I meant how to make the objects become part of the GUI. I can't see how do I create the object, then draw it as part of the GUI.
 
I'm not sure I'm understanding what you want.

It looked like you wanted to draw something that stays fixed in the same location on the screen, while the view rotates.

For example a mini-map or compass.

If you are wanting the object to be drawn as part of the GUI, you create the object as you usually would, just use the Draw GUI Event to draw it. Bear in mind, gui co-ordinates are from 0,0 to your gui width and gui height.

Also, you might want to include a blank Draw Event, so it doesn't get drawn in the game layer as well as the GUI Layer.
 
Top