Page 1 of 1

Gravity and MoveTo problem

PostPosted: Wed Jul 31, 2013 2:59 am
by unknown24
First in my game i use gravity script in player draw actor event here,
yvelocity+=0.5;

I want to use player to move left and right following mouse click, i add sensor actor to do that an use this script in mouse button down event:
MoveTo("player",xmouse,player.yscreen,5.000000,"view","");

Here the problem, i test game when i left click mouse, player move to the xmouse like teleport, it's move from point A to point B without path.
How to fix that?
Please help me, please post here too if my problem is confused, i will post my problem in youtube and post the link here,,, or try this code yourself,,
sorry i can't speak english well

Re: Gravity and MoveTo problem

PostPosted: Wed Jul 31, 2013 3:25 am
by skydereign
Sadly this is a bug in gE. It has to do with mixing velocity and MoveTo. If you create your own yvelocity variable and use that to offset y in the draw actor, it should work.
Code: Select all
yvel += 0.5;
y += yvel;

Do note yvel should be a double or float. Also you'll need to set yvel instead of yvelocity for all cases, which can take a bit more work when dealing with collisions.

Re: Gravity and MoveTo problem

PostPosted: Wed Jul 31, 2013 4:01 am
by unknown24
skydereign wrote:Sadly this is a bug in gE. It has to do with mixing velocity and MoveTo. If you create your own yvelocity variable and use that to offset y in the draw actor, it should work.
Code: Select all
yvel += 0.5;
y += yvel;

Do note yvel should be a double or float. Also you'll need to set yvel instead of yvelocity for all cases, which can take a bit more work when dealing with collisions.


First thank's for your fast respone and help, i make variabel in script editor, the type data is real, i follow your guide but it's not work it's move slowly and then stop not in the right xmouse, afterthat suddenly it go down through the platform,,
and i dont understand with statement that i bold in quote above,,

Re: Gravity and MoveTo problem

PostPosted: Wed Jul 31, 2013 6:31 am
by skydereign
Ah, forgot about a different problem with MoveTo. I would recommend not using MoveTo at all (in my experience I've run into a lot of different bugs caused by it). Instead I would create some simulacrum with variables. Ways to do this can get complex, so I won't go into it unless you really need it. But, a simpler method would be to set the player actor's state, and have it move towards xmouse.
unknown24 wrote:then stop not in the right xmouse

Do you want it to move to the xmouse when the button is clicked, or till it reaches the mouse? If you want the latter, this method will help with that. The main idea is that instead of MoveTo, on the click you set some variable that you can then use in the player's draw actor.
player -> Draw Actor -> Script Editor
Code: Select all
yvelocity += 0.5;

if(player_state==1) // player is set to move
{
    x += 5*((x < xmouse) - (x > xmouse)); // player will move either left or right depending on where the mouse is
    if(abs(xscreen-xmouse)<5)
    {
        player_state = 0; // stop moving
    }
}

Re: Gravity and MoveTo problem

PostPosted: Wed Jul 31, 2013 5:20 pm
by unknown24
yes, I want it to move to the xmouse when the button is clicked,, i want to add jumping later it my reason to work with gravity,,,

I follow your code again, but error undeclare identifier player_state,, here the image,,
Image

Re: Gravity and MoveTo problem

PostPosted: Thu Aug 01, 2013 1:29 am
by skydereign
You need to create the variable player_state. All it is doing is a variable that you set to 1 when you want the player to move to xmouse.

Re: Gravity and MoveTo problem

PostPosted: Fri Aug 02, 2013 2:51 am
by unknown24
Amazing,,,
Thank it work but there is bug on the left mouse,,,
I think i can soved that,,, thx :D

Re: Gravity and MoveTo problem

PostPosted: Fri Aug 02, 2013 4:26 am
by unknown24
First i add variable called opt,,
Onmouse down event i add this script:
Code: Select all
if (player.xscreen>xmouse)
{
   opt=-5;
} else
{
   opt=5;
};

player_state=1


and On Player draw actor event i add this script:
Code: Select all
yvelocity+=0.5;

if(player_state==1)
{
   x = x+opt;
   if (abs(xscreen-xmouse) < 5)
   {
      player_state=0;
   }
}


Thx skydereign,,