Page 1 of 1

view follow an Actor Problem

PostPosted: Wed Jun 18, 2014 10:38 am
by Behdadsoft
Hi.
I want follow view according to Player Move. I create a actor and add this code:

Draw Actor => Script Editor :

Code: Select all
int weight =5;
x = ((weight - 1)*x +Player.x)/weight;


but when play the game view move to left and make a black screen.i change weight value but no give good reason. how can fix it?

Thanks.

Re: view follow an Actor Problem

PostPosted: Wed Jun 18, 2014 3:21 pm
by DeltaLeeds
Behdadsoft wrote:Hi.
I want follow view according to Player Move. I create a actor and add this code:

Draw Actor => Script Editor :

Code: Select all
int weight =5;
x = ((weight - 1)*x +Player.x)/weight;


but when play the game view move to left and make a black screen.i change weight value but no give good reason. how can fix it?

Thanks.

Hello Behdad! You don't need to use draw actor and stuff, you can just make view's parent the player actor and it will follow the player automatically. :)

Re: view follow an Actor Problem

PostPosted: Thu Jun 19, 2014 12:18 pm
by Behdadsoft
Thanks jonathang is good idea but still show a little Black screen when Player Move back to Left.

Re: view follow an Actor Problem

PostPosted: Thu Jun 19, 2014 12:26 pm
by Goettsch
Behdadsoft wrote:Thanks jonathang is good idea but still show a little Black screen when Player Move back to Left.

You can put other tiles in the black space

Re: view follow an Actor Problem

PostPosted: Fri Jun 20, 2014 7:01 pm
by Behdadsoft
You can put other tiles in the black space


this is not good idea because when I climp up ladder the view move to up and make half black screen.I can't put any thing in sky.

Re: view follow an Actor Problem

PostPosted: Sat Jun 21, 2014 10:27 am
by Goettsch
Then, create two wire frame regions, make them as tall as the view, and put one of them at player.x-=30 and the other at player.x+=30
Then use this code:
Player-> collision -> right side of the first wire frame region,repeat: yes
View.x-=(the speed of the player)

Then add this code to :player-> collision -> left side of the second wire frame region, repeat: yes
View.x+=(the speed of the player)

then set the two wire frame regions to be parents of the view

Re: view follow an Actor Problem

PostPosted: Fri Jul 25, 2014 4:32 am
by Zivouhr
Sounds like good advice.

I usually have the view have the player as the parent to simplify things, but there is a demo created on this forum, where the stick figure they created moves left or right and the screen scrolls left or right once they hit one of those side regions parented to the view I think. That allows for some slack in the player's left right movement, but if I remember, the demo will give some ideas about not having the view parented to the player, but still follows the player.

Otherwise, you could possibly just assign the same X speed that the player has for his x movement (left or right), without parenting the view. Here's another suggestion; simple way;

View/keydown/left/repeat On/Script editor:
x-=6; // - makes the view go left here. // = notes, not actual code, to inform those new to coding.

View/keydown/right/repeat On/Script editor:
x+=6; //+ makes view go right.

--------

player/keydown/left/repeat On/Script editor:
x-=6; // - makes the player go left here. // = notes, not actual code, to inform those new to coding.

player/keydown/right/repeat On/Script editor:
x+=6; //+ makes player go right.


--------

That will allow the player to move freely left or right, and the camera VIEW will follow those movements, but only if the player is not stopped by a wall. In that case, if you keep pressing right, and the player is stopped, using this coding, then the view will keep moving independent of the player, eventually leaving the player offscreen which wouldn't be the goal.

In that case, you'd definitely want Goettsch's idea, that sounds like it will work, though I haven't tested this out yet.

Just trying to offer some ideas, as I'm learning myself, having completed only my first game.