Hi, I have few questions about GS. Most of them easy, I hope.
cbt
Member Posts: 644
Hi guys,
I've discovered GS about two months ago, and than I bought a Mac, and about 20 days now, I've been playing with GS. And I had a lot of fun. I've made few applications but no games. I thought I was ready for the real work and decided to make an easy game today, but I can't do a thing. Here is the thing:
First of all, sorry for my English. Now, what I'm trying to do is;
I have actors called: "CAR", "BALL" and "SPAWNER".
I'm spawning the actor "CAR" in random (1,4) seconds via the "SPAWNER" and giving it a linear X acceleration. I want the "CAR" to slow down when it gets close to "BALL" and stop when collides.
And I want to "CAR" to stop few pixels before the previous spawned "CAR". ("SPAWNER" spawns every "CAR" in the same line and in the same direction. They lineup back to back but, I don't want them to touch together, I want to put a little space between two cars.)
(To make the "CAR" accelerate and stop when collides with "BALL")
"CAR" has;
-When all conditions are valid;
-Actor overlaps or collides with "BALL" ;
-Constrain Att. Self.Motion.Linear.X To "0"
-Otherwise;
-Acclerate 200
(To make the "CAR" slowdown when gets close)
-When all conditions are valid;
-Self.Position.X > Game.BALLposition.X - 100
-Change Velocity to Speed 9
(To make the "CAR" stop when collides with the previous spawned "CAR")
-Overlaps or Collides With "CAR"
-Constrain Att. Self.Motion.Linear.X To "0"
But when I do it like this, "CAR" stops when collided with other "CAR" but a few seconds later, it keeps going with a little velocity. Than I added this to give a little space between two "CAR" actors;
-Actor overlaps or collides with "CAR"
-Change Att. Self.Position.X to Self.Position.X - 30
But it just f*cks up all. What should I do? Thanks in advance..
I've discovered GS about two months ago, and than I bought a Mac, and about 20 days now, I've been playing with GS. And I had a lot of fun. I've made few applications but no games. I thought I was ready for the real work and decided to make an easy game today, but I can't do a thing. Here is the thing:
First of all, sorry for my English. Now, what I'm trying to do is;
I have actors called: "CAR", "BALL" and "SPAWNER".
I'm spawning the actor "CAR" in random (1,4) seconds via the "SPAWNER" and giving it a linear X acceleration. I want the "CAR" to slow down when it gets close to "BALL" and stop when collides.
And I want to "CAR" to stop few pixels before the previous spawned "CAR". ("SPAWNER" spawns every "CAR" in the same line and in the same direction. They lineup back to back but, I don't want them to touch together, I want to put a little space between two cars.)
(To make the "CAR" accelerate and stop when collides with "BALL")
"CAR" has;
-When all conditions are valid;
-Actor overlaps or collides with "BALL" ;
-Constrain Att. Self.Motion.Linear.X To "0"
-Otherwise;
-Acclerate 200
(To make the "CAR" slowdown when gets close)
-When all conditions are valid;
-Self.Position.X > Game.BALLposition.X - 100
-Change Velocity to Speed 9
(To make the "CAR" stop when collides with the previous spawned "CAR")
-Overlaps or Collides With "CAR"
-Constrain Att. Self.Motion.Linear.X To "0"
But when I do it like this, "CAR" stops when collided with other "CAR" but a few seconds later, it keeps going with a little velocity. Than I added this to give a little space between two "CAR" actors;
-Actor overlaps or collides with "CAR"
-Change Att. Self.Position.X to Self.Position.X - 30
But it just f*cks up all. What should I do? Thanks in advance..
Comments
for the second one...try setting the "Drag" of the car to the real time inverse of the distance from the ball.
And to be honest, I didn't understand the second thing you said
In this case...set it to an inverse parabolic algorithm.
Make 2 Constrain Attributes on the car.
1) game.XdistFrmBall = self.position.X - game.targetXposition (constrained from the target)
2) self.myNewVelocityX = floor(sqrt(game.XdistFrmBall*game.XdistFrmBall*game.XdistFrmBall)/5)
note: the 5 at the end of the algo is a scaling factor to give you different results scales. Reducing the number makes the results larger while increasing it shrinks the results.
so if the car is 100 X distance from the ball, the new velocity would be 200 (the floor of the algo above)
Then when the car is 50 X from the ball, the new velocity would be 70.
This type of scaling algo will make the reduction exponential.
Then you set a timer inside a Rule,
If self.velocity.X > 0
Every # seconds (perhaps 0.25)
ChangeVelocity self.velocity.X to self.myNewVelocityX
Otherwise
changeVelocity to 0
If none of this makes sense...read up on Expressions in the reference section.
Hope this helps someone reading.
These reverse algos are very handy when trying to scale values in a gradual/parabolic way without getting into complex trigonometry calcs.
The X position of an actor is relevant to its center point...if the actors are still overlapping...it is because their center points haven't touched.
To avoid this...you have to track their X Position plus half their width to find their edges.