View delay

You must understand the Game Editor concepts, before post here.

View delay

Postby ikarus » Fri Aug 19, 2011 6:10 pm

Does anyone got any good techniques to make the view follow an actor but with a delay? Like where the actor moves a bit first before the view catches up? I've tried the built in tutorials but they don't work lol. A dialog pops up about the ipod and frame size and it doesn't look like the tutorial expects it and continues clicking around doing nothing lol
>>>>>>>>>>>>>>>>>>>>> http://www.code1011.com <<<<<<<<<<<<<<<<<<<<<<<
ikarus
 
Posts: 143
Joined: Fri Aug 12, 2011 3:06 am
Score: 11 Give a positive score

Re: View delay

Postby Jagmaster » Fri Aug 19, 2011 7:08 pm

Yes that is annoying T_T

Here is the code I use:

Code: Select all
int xspeed = 10;
x = ((xspeed - 1)*x + player.x)/xspeed;

I basically paused the tutorial before it got messed up with the Iphone message a long time ago. One thing to note: The view gets messed up when you parent the actor the view is following to another actor. I would like to know how to fix this if anyone knows.
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: View delay

Postby skydereign » Fri Aug 19, 2011 8:09 pm

Well the parenting problem has to do with the actor coordinates. When an actor is parented, it uses a different xy coordinate system where the parent is 0,0. You can avoid this by using xscreen, and the view's x. That is to say the actual position of the actor is equal to the actor's xscreen plus the view's x. So this should work.
Code: Select all
int xspeed = 10;
x=((xspeed-1)*x+player.xscreen+x)/xspeed;

I used this in a game once, might not be the best way, but it worked for me at the time (a while ago).
Code: Select all
xvelocity=player.xvelocity/2 - (x+width*0.25>player.x)*5 + (x+width*0.75<player.x)*5;

The 5 is really half the speed the player moves at. All this does is make it move half the speed of the player, and if the actor is too close to either side of the view, it speeds it up to the same as the player as to prevent the player from leaving the view.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: View delay

Postby Jagmaster » Fri Aug 19, 2011 8:50 pm

Sweet! Thanks Sky! :o
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: View delay

Postby Game A Gogo » Sat Aug 20, 2011 2:39 am

I know sky and Jagmaster probably answered this really well... but I'll trow in a code I used a year ago:

Code: Select all
view.angle=direction(view.x+(view.width*.5)-(MP_Dir*48),view.y+(view.height*.5)+16,x,y);
if(distance(view.x+(view.width*.5)-(MP_Dir*48),view.y+(view.height*.5)+16,x,y)<92)view.directional_velocity=distance(view.x+(view.width*.5)-(MP_Dir*48),view.y+(view.height*.5)+16,x,y)*0.04;
else view.directional_velocity=distance(view.x+(view.width*.5)-(MP_Dir*48),view.y+(view.height*.5)+16,x,y)*0.08;

Put this code on the actor you want the view to follow.
MP_Dir is MainPlayer_Direction. So you need a variable that will be -1 when it's left and 1 when it's right so this might not be for you.

This code should create a really smooth movement but still allows you to see where you're going. Modify the multipliers (the *0.04 for the slow speed and *0.08 for the fast speed) to fit to your game. The value 48 (all of them) represent the offset of the screen depending on which way the player is facing. The value +16 (all of them) represent the vertical offset of the screen and the 92 inside the if statement represents the distance the view should start moving faster. whith that said I suppose I could make this code so it makes things cleaner....

Code: Select all
int Hori_Offset=48;//horizontal offset
int Vert_Offset=16;//vertical offset
int HurryDist=96;//Distance at which the view starts moving faster
double SlowFact=0.04;//The factor at which the speed is reduced (lower=slower)
double FastFact=0.08;//The factor at which the speed is augmented
//Note, a factor of 1 means the view will move instantly towards the player and 0 means it won't move at all.
view.angle=direction(view.x+(view.width*.5)-(MP_Dir*Hori_Offset),view.y+(view.height*.5)+Vert_Offset,x,y);
if(distance(view.x+(view.width*.5)-(MP_Dir*Hori_Offset),view.y+(view.height*.5)+Vert_Offset,x,y)<HurryDist)view.directional_velocity=distance(view.x+(view.width*.5)-(MP_Dir*Hori_Offset),view.y+(view.height*.5)+Vert_Offset,x,y)*SlowFact;
else view.directional_velocity=distance(view.x+(view.width*.5)-(MP_Dir*Hori_Offset),view.y+(view.height*.5)+Vert_Offset,x,y)*FastFact;


Simply change the values to get your desired effect....

Although this method seems fancy, it can be annoying depending on your gameplay.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: View delay

Postby ikarus » Sat Aug 20, 2011 4:21 pm

Wow so many options :o, experimentation commence! :D
>>>>>>>>>>>>>>>>>>>>> http://www.code1011.com <<<<<<<<<<<<<<<<<<<<<<<
ikarus
 
Posts: 143
Joined: Fri Aug 12, 2011 3:06 am
Score: 11 Give a positive score

Re: View delay

Postby Jagmaster » Sun Aug 21, 2011 2:48 am

Wow Gogo, That's the longest view moving code I ever heard! (eats pickle) I will give that a try sometime. :D
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: View delay

Postby ikarus » Sun Aug 21, 2011 8:39 am

By the way Skydereign, your code works absolutely perfectly! Haven't tried yours Game A Gogo, the lack of copy/paste from webpage into ge editor keeps me too scared to get my hands that dirty in that uber delish code lol
>>>>>>>>>>>>>>>>>>>>> http://www.code1011.com <<<<<<<<<<<<<<<<<<<<<<<
ikarus
 
Posts: 143
Joined: Fri Aug 12, 2011 3:06 am
Score: 11 Give a positive score

Re: View delay

Postby Jagmaster » Sun Aug 21, 2011 12:47 pm

Click the text that says select all, then hit ctrl+c then go into the script editor and hit ctrl+v.

Btw, Gag, I can't get your code to work, I set up a variable called MP_Dir (integer, global) and set it to positive or negative 1 for right or left, but when I executed the game, the view went haywire. :|

@Sky: The second code you sent works great, but for the first one, how would you center the player with this code? When I put + 320 at the end of the line, the screen also went haywire. :| :|

I really want to get these methods to work because I'm so fed up with with the ones I'm using (with the parenting issue).
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: View delay

Postby Game A Gogo » Sun Aug 21, 2011 3:14 pm

now I might have made the second code wrong... so let me debug it... *debugs* actually the code is correct, I was able to implant it in a second in an old game of mine.

if you're having problem with the MP_Dir, here's an addition of code you can use with the provided codes:
Code: Select all
int MP_Dir;
if(xvelocity>0)MP_Dir=1;
else if(xvelocity<0)MP_Dir=-1;

Now this will detect which was the last position the player pointed to depending on his speed.

Well my code will not fix your parenting issue if the player you need to follow is parented to something.
The view shouldn't be parented to anything either.

Also make sure that the code is inside the player's draw actor, if the player is parented to something, put it in the parent of the player instead (like if you have a collision mask actor).

as my code uses x/y coordinates and not xscreen/yscreen coordinate

Now the code could easily be modified to work with screen coordinates rather than actor coordinates by adding "screen" to all the x and y variables.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: View delay

Postby Jagmaster » Sun Aug 21, 2011 4:10 pm

Oh..... I was had that code in draw actor for view not the player. :lol: That makes sense why it would go haywire. *view tries to move toward it's own coordinates* :P

Thanks for the info. I guess I could use the cname of the parent and tell the view to follow that. The parenting was to quickly fix a moving platform bug without xoffset or anything like that.
Last edited by Jagmaster on Sun Aug 21, 2011 4:59 pm, edited 1 time in total.
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: View delay

Postby Game A Gogo » Sun Aug 21, 2011 4:15 pm

Then simply add "screen" to all coordinates to make xscreen and yscreen, parenting will not be an issue then!

EDIT: also couldn't you use xvelocity=collide.xvelocity; when colliding with the platform? with xvelocity=0; when it stops colliding of course.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: View delay

Postby Jagmaster » Sun Aug 21, 2011 4:59 pm

Game A Gogo wrote:
EDIT: also couldn't you use xvelocity=collide.xvelocity; when colliding with the platform? with xvelocity=0; when it stops colliding of course.

:lol: Yes, I should of done that in the first place. That would make my code less of a Rube-Goldberg machine.

Thanks, I will try the screen coordinates thing again.
User avatar
Jagmaster
 
Posts: 875
Joined: Sun May 08, 2011 4:14 pm
Location: Not where you think.
Score: 82 Give a positive score

Re: View delay

Postby ikarus » Mon Aug 22, 2011 4:35 am

Jagmaster wrote:Click the text that says select all, then hit ctrl+c then go into the script editor and hit ctrl+v.

Btw, Gag, I can't get your code to work, I set up a variable called MP_Dir (integer, global) and set it to positive or negative 1 for right or left, but when I executed the game, the view went haywire. :|

@Sky: The second code you sent works great, but for the first one, how would you center the player with this code? When I put + 320 at the end of the line, the screen also went haywire. :| :|

I really want to get these methods to work because I'm so fed up with with the ones I'm using (with the parenting issue).


yep, not working??? Maybe it's only a linux thing
>>>>>>>>>>>>>>>>>>>>> http://www.code1011.com <<<<<<<<<<<<<<<<<<<<<<<
ikarus
 
Posts: 143
Joined: Fri Aug 12, 2011 3:06 am
Score: 11 Give a positive score

Re: View delay

Postby Game A Gogo » Mon Aug 22, 2011 1:44 pm

funny it works perfectly for me S: are you sure you're incorporating my code properly?
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest