Screen following object

Tutorials and guides for Plazma Burst and community features.

Screen following object

Postby darkstar 1 » 10 June 2018, 22:13

Ok, so after some thinking I've found out how to make an object always move to the same spot on the screen.

Open sourced version: http://www.plazmaburst2.com/?s=9&a=&m=darkstar%201-screen%20following%20object&id=891007

How to do it:
Spoiler: Show More
1) First of all you create a fake movable, barrel, ... (whatever you want to move to that location on the screen)

2) You move a region to the player and a region to the cursor and set the X and Y coordinates of both of them to variable values (4 variables in total) (then you set two additional variables to the X and Y coordinate of the player for further calculations).

3) What we have to do now is substracting the X and Y value of the player with the X and Y value of the cursor.
I order to do this we will make the additional variables negative add these values to the X and Y value of the cursor (= the same as substracting).
Then you simply devide the two cursor variables by 2.

4) The next thing you'll want to do adding the distance you want the object to be (if the cursor would be at the same spot as the player) to the X and Y coordinates of the player. And then adding the X and Y coordinates of the cursor to the X and Y coordinates of the player.

5) Now move a third region to the new X and Y coordinates and move the object to it.


Explanation:
Spoiler: Show More
When the cursor would be in the middle of the screen, it would be exactly on the player. The distance between the player and, for example, the right end of the screen is half the lenght of the screen.
If you move the cursor to the right end of the screen, half a lenght of the total screen gets added between the player and this end.

So the middle of the screen is always in exact the middle of the distance between the player and cursor.

In order to get an object moving to exact the same spot on the screen you simply add half of the distance between player and cursor to the coordinates of this object.


Example of what it can be used for:
- Ammo display: http://www.plazmaburst2.com/?s=2&map=darkstar%201-ammo4
http://www.plazmaburst2.com/?s=2&map=darkstar%201-pixels
User avatar
darkstar 1
Lite Marine [800]
 
Posts: 801
Joined: 13 September 2014, 13:20
Location: Here... or there :|

Re: Screen following object

Postby wreak » 10 June 2018, 22:43

To be honest, it's kinda glitchy, especially with the ammo display as it limits where you can place your cursor. I still like how genius the idea is considering I don't have to remember the amount of ammo I have in my gun or I can use this for extended GUI.
wreak
User avatar
wreak
Noir Lime [600]
 
Posts: 640
Joined: 23 January 2015, 02:01

Re: Screen following object

Postby darkstar 1 » 13 June 2018, 21:36

wreak wrote:... especially with the ammo display as it limits where you can place your cursor. ...

What exactly do you mean with this? I don't see how it limites the places where you can put your cursor since those are fake walls, barrels don't seem to collide with walls or the player either.
http://www.plazmaburst2.com/?s=2&map=darkstar%201-pixels
User avatar
darkstar 1
Lite Marine [800]
 
Posts: 801
Joined: 13 September 2014, 13:20
Location: Here... or there :|

Re: Screen following object

Postby wreak » 13 June 2018, 22:50

darkstar 1 wrote:
wreak wrote:... especially with the ammo display as it limits where you can place your cursor. ...

What exactly do you mean with this? I don't see how it limites the places where you can put your cursor since those are fake walls, barrels don't seem to collide with walls or the player either.

wreak
User avatar
wreak
Noir Lime [600]
 
Posts: 640
Joined: 23 January 2015, 02:01

Re: Screen following object

Postby darkstar 1 » 14 June 2018, 06:27

What settings were you using when that happened? I've tried it with low quality and 30fps and on high and 60fps and in both cases that didn't happen to me. (Only when I pressed X)
http://www.plazmaburst2.com/?s=2&map=darkstar%201-pixels
User avatar
darkstar 1
Lite Marine [800]
 
Posts: 801
Joined: 13 September 2014, 13:20
Location: Here... or there :|


Return to Tutorials

Who is online

Users browsing this forum: No registered users