Gravity and MoveTo problem

Game Editor comments and discussion.

Gravity and MoveTo problem

Postby unknown24 » Wed Jul 31, 2013 2:59 am

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
unknown24
 
Posts: 15
Joined: Fri Jul 19, 2013 4:25 pm
Score: 0 Give a positive score

Re: Gravity and MoveTo problem

Postby skydereign » Wed Jul 31, 2013 3:25 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Gravity and MoveTo problem

Postby unknown24 » Wed Jul 31, 2013 4:01 am

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,,
unknown24
 
Posts: 15
Joined: Fri Jul 19, 2013 4:25 pm
Score: 0 Give a positive score

Re: Gravity and MoveTo problem

Postby skydereign » Wed Jul 31, 2013 6:31 am

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
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Gravity and MoveTo problem

Postby unknown24 » Wed Jul 31, 2013 5:20 pm

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
unknown24
 
Posts: 15
Joined: Fri Jul 19, 2013 4:25 pm
Score: 0 Give a positive score

Re: Gravity and MoveTo problem

Postby skydereign » Thu Aug 01, 2013 1:29 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Gravity and MoveTo problem

Postby unknown24 » Fri Aug 02, 2013 2:51 am

Amazing,,,
Thank it work but there is bug on the left mouse,,,
I think i can soved that,,, thx :D
unknown24
 
Posts: 15
Joined: Fri Jul 19, 2013 4:25 pm
Score: 0 Give a positive score

Re: Gravity and MoveTo problem

Postby unknown24 » Fri Aug 02, 2013 4:26 am

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,,
unknown24
 
Posts: 15
Joined: Fri Jul 19, 2013 4:25 pm
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest