Follow view without parenting or moving bug

Learn how to make certain types of games and use gameEditor.

Follow view without parenting or moving bug

Postby Hblade » Wed May 29, 2013 3:31 am

If you want to "stick" something to the view without it glitching out when moving (or without parenting) the solution is simpler than you think :)

All you have to do is put this in draw actor of the follower:
Code: Select all
x=view.x/1;
y=view.y/1;


You might have to do this if you have a background thats large:
Code: Select all
x=view.x/1+(width/2);
y=view.y/1+(height/2);


Why /1? Because without that, you can see the background move a bit when the view moves, but by dividing it by 1 for some reason its instant :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Follow view without parenting or moving bug

Postby skydereign » Wed May 29, 2013 4:00 am

Hblade wrote:Why /1? Because without that, you can see the background move a bit when the view moves, but by dividing it by 1 for some reason its instant :)

Dividing by 1 makes it cast it to an int (losing the floating point). This helps because x and y values are doubles, which gE rounds up or down when actually drawing.

Hblade wrote:
Code: Select all
x=view.x/1;
y=view.y/1;

You can do the same thing with xscreen, and not need to cast it to an int.
Code: Select all
xscreen = 0;
yscreen = 0;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Follow view without parenting or moving bug

Postby Hblade » Wed May 29, 2013 4:27 am

Thanks lol, I thought xscreen=0 and yscreen=0 would cause the same effect as the moving glitch (If the view moves super fast, the background moves differently than the view, which is why somehow I discovered /1 prevents that and sticks it ^_^ :) ) But yeah thanks, didn't know xscreen=0 is different than x=view.x :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Follow view without parenting or moving bug

Postby skydereign » Wed May 29, 2013 5:14 am

Ah, actually there does seem to be a slight difference. Setting xscreen essentially sets it to the current view position, but setting x to view.x sets it after the view has moved. This is rather odd, and probably shouldn't happen, but that's how it currently stands (which is why view.x and xcreen do different things for you). Though the /1 does not do anything if the view is moving at integer amounts, again due to no need to cast.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Follow view without parenting or moving bug

Postby Hblade » Wed May 29, 2013 5:18 am

Ahh right, but wouldn't you be able to do a similar effect using round? x=round(view.x); that would be the same as /1 correct? or xscreen
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Follow view without parenting or moving bug

Postby skydereign » Wed May 29, 2013 5:24 am

No, rounding rounds up and down depending on the floating point (round(5.9) = 6). Dividing by 1 casts it as an int, meaning 5.9/1 = 5. You could use floor instead though.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Follow view without parenting or moving bug

Postby Hblade » Wed May 29, 2013 5:48 am

Oh! Never knew what floor did :) So, floor(2.3); would mean 2, as well as floor(2.9). I see, so floor basically completely removes the decimal(s).
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Follow view without parenting or moving bug

Postby bat78 » Mon Jun 03, 2013 8:39 pm

it works also with ceil(), but it will be with 1 bit slower.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Follow view without parenting or moving bug

Postby Hblade » Tue Jun 04, 2013 3:19 am

So /1 is the best way :3?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Follow view without parenting or moving bug

Postby skydereign » Tue Jun 04, 2013 4:39 am

No, if you want to cast it, actually do the cast (or use floor). Dividing by 1 is just weird.
Code: Select all
int var = (int)4.9;
// var is set equal to 4
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Follow view without parenting or moving bug

Postby Hblade » Tue Jun 04, 2013 5:14 am

Thanks :) Weird that now when I try, it actually keeps up O.o no matter how I do it. Lol this was confusing
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest