Page 1 of 1
stoping objects
Posted:
Sun Nov 04, 2012 3:36 pm
by BogdansB
hey,
i have an actor , a ball , who ,when he collides with the player , rolls away. now i want to make him slowly stop after maybe 5 seconds. how do i do it?
thanks
Re: stoping objects
Posted:
Sun Nov 04, 2012 7:21 pm
by skydereign
I assume the actor is moving from velocity variables (instead of x+= ) since you mentioned collisions. One of the usual methods of decelerating is to multiply the velocity by a number slightly less than one. You only want that code to trigger after the collision, so you should use an actor variable to determine if the ball should slow down (and set it equal to 1 on the collision).
player -> Collision with ball -> Script Editor
- Code: Select all
// your collision code
collide.slow_down = 1;
ball -> Draw Actor -> Script Editor
- Code: Select all
if(slow_down==1)
{
directional_velocity=directional_velocity*0.99;
if(directional_velocity==0)
{
slow_down=0;
}
}
Re: stoping objects
Posted:
Tue Nov 06, 2012 7:04 pm
by BogdansB
thanks .
now in the same game, when you make a score (soccer) the ball's position is x=0 and y=0. now when i play the game , the ball , when i score, goes from the 0,0 position with the same velocity how it went to the goal :S how do i do the ball standing on the 0 0 position?
i tried with xvelocity=0; yvelocity=0; doesnt work: the ball goes reaallyyy fast outside the view when the next "round" starts ...
Re: stoping objects
Posted:
Tue Nov 06, 2012 8:48 pm
by skydereign
Setting the actor's velocity variables to 0 should stop it. So either something else is increasing the variables, or you aren't setting the correct actor's xvelocity and yvelocity to 0. You'll need to post more about your setup.
Re: stoping objects
Posted:
Tue Nov 06, 2012 11:08 pm
by Soullem
Hey I made a soccer game that sounds like it could help you out a lot! its called 2 man soccer, and its in game development . Also when you are setting the velocity, what actor has the script for this? if it isn't the ball try adding
ball.xvelocity=0;
ball.yvelocity=0;
Heres a link to my game
http://game-editor.com/forum/viewtopic.php?f=4&t=12365
Re: stoping objects
Posted:
Wed Nov 07, 2012 3:34 pm
by BogdansB
hmm its not in the ball actor but i did ball.x ..... and it still glitches. and i still dont know what the problem is , even after watching your game which is really good
Re: stoping objects
Posted:
Thu Nov 08, 2012 2:34 am
by Soullem
Wait are you using directional velocity in your ball movement script? If so you might have to set
ball.directional_velocity=0;
Im not sure though, and thanks for the compliment
Re: stoping objects
Posted:
Thu Nov 08, 2012 2:51 am
by skydereign
Setting any velocity to zero will stop the actor, even if it uses the other velocity scheme. But BogdansB, we can't help you unless you post more about your setup. This should be pretty trivial, but unless we actually know what is happening in your game, all we can do is guess. If you can post the ged and data. Otherwise post all the code that handles movement for the ball.
Re: stoping objects
Posted:
Fri Nov 09, 2012 6:57 pm
by BogdansB
here it is
Re: stoping objects
Posted:
Fri Nov 09, 2012 7:55 pm
by skydereign
So this is caused by a bug in gE. The slow down code I gave you references directional_velocity in the ball's draw actor. This can cause problems when moving the actor, because xvelocity and yvelocity are updated automatically when the actor is moved. Namely if you put x+=5 in an actor's draw event, they will have an xvelocity of 5, even if you didn't ever set it. Easiest way around it is just to create a new ball actor. So in bg's timer event, destroy the ball actor, and create one in the center.
Re: stoping objects
Posted:
Sat Nov 10, 2012 8:40 am
by BogdansB
ok its working
Re: stoping objects
Posted:
Tue Nov 13, 2012 5:35 pm
by BogdansB
and another problem :S
since i made my score growing untill 10 and then get 0 , the code doesn'T work
- Code: Select all
if(green_points.textNumber==10)
{
green_points.textNumber=0;
}
whats wrong?
Re: stoping objects
Posted:
Tue Nov 13, 2012 9:09 pm
by skydereign
textNumber isn't normal. Therefore, I don't recommend you use textNumber like a normal variable. Instead you should make a variable green_score or similar, and use that instead. Using it like you have has been reported to give problems (probably due to textNumber's questionable type), so that could be the reason.
Re: stoping objects
Posted:
Fri Nov 16, 2012 4:54 pm
by BogdansB
works , thanks