Page 1 of 2
Ricochet and Turbulence Effect
Posted:
Sat Feb 02, 2008 3:28 am
by MudRat_02
Ok, i have two effects I'm trying to get into two separate sections of a game I'm making (but have been thus far unsuccessful!)
First effect is turbulence. In the game, you're in a fighter cockpit, and you're aim is to bring your crosshair onto a target long enough to lock your missiles on (which is when you pass this level). However, I want the crosshair to randomly move and 'buck' about to simulate the turbulence that your aircraft is experiencing. I have a very VERY primitive version working, where the crosshair randomly and statically flicks about the screen which is useless. What I need is the crosshair to be randomly trying to move in a different direction from the target (and you have to try and counter this independent movement) and accelerating (as opposed to instantly boosting off at a given velocity!). And every random amount of time, slowing and accelerating in a different direction. I want the acceleration and ultimate velocity to increase as well of the frequency of direction change to increase as the game goes on, and thus your level of control decrease. I have a pic below (this is game 2)
And the next game is easier. I just want the target circle to bounce off the edges of screen at a 45 degree trajectory while you try and keep your target on it (game 1)
The crosshairs .etc are only to represent the underlying mechanics of the game, I'll add the eye candy later
Thanks in advance for any help!
Re: Ricochet and Turbulence Effect
Posted:
Sat Feb 02, 2008 11:02 pm
by zygoth
I think this is what you want...
Draw Actor --> Crosshair
if(xvelocity <=3 && xvelocity >= -3)xvelocity = xvelocity + (rand(3) -2);
if(yvelocity <=3 && yvelocity >= -3)yvelocity = yvelocity + (rand(3) -2);
if(xvelocity >=4)xvelocity = xvelocity - 1;
if(xvelocity <=-4)xvelocity = xvelocity + 1;
if(yvelocity >=4)yvelocity = yvelocity - 1;
if(yvelocity <=-4)yvelocity = yvelocity + 1;
This seems a clumsy way of doing it but I think it will work...if you want the values to be controllable replace them with variables and set timers to increase them every so often.
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 1:40 am
by MudRat_02
I tried your code, but unfortunately It didn't work. Initially the crosshair moves away from the center, but as soon as I press enter (action event to control the crosshair) it all stops, and I have complete control. This is the code i was using before, but all it does is make the crosshair randomly skip about
fourChance = rand(4); //This is used to randomly select what direction to move in (x,y, -x,y, x,-y, -x.-y)
turbulencex = 10 + rand(5);
turbulencey = 10 + rand(5);
i=rand(10);
if (i==0){
if (fourChance == 1)
{
x += rand(turbulencex);
y += rand(turbulencey);
}
else if (fourChance == 2)
{
x -= rand(turbulencex);
y -= rand(turbulencey);
}
else if (fourChance == 3)
{
x -= rand(turbulencex);
y += rand(turbulencey);
}
else if (fourChance == 4)
{
x += rand(turbulencex);
y -= rand(turbulencey);
}
else
{
x = x;
y = y;
}
}
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 8:58 am
by Bee-Ant
I wanna help...but...I hate reading a long text...can you explain it shorty?
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 10:24 am
by MudRat_02
Haha ok, here's it is in short.
I need to make an object onscreen move about randomly away from the center (doesnt matter what direction, just as long as it isnt getting any closer to the middle). It needs to be smooth (to simulate turbulence), and the aim is to try and counter the effects of turbulence to keep the object in the middle of the screen.
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 10:29 am
by Bee-Ant
Very very simple...
make an actor called "center" parented with view actor...place it in the center position.
center>DrawActor>ScriptEditor>
- Code: Select all
VisibilityState("Event Actor", DONT_DRAW_ONLY);
MovingObject>DrawActor>ScriptEditor
- Code: Select all
if(x<center.x)
{
xvelocity+=1;
}
if(x>center.x)
{
xvelocity-=1;
}
if(y<center.y)
{
yvelocity+=1;
}
if(y>center.y)
{
yvelocity-=1;
}
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 10:30 am
by Bee-Ant
Still confused???
I'll make the demo...
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 1:53 pm
by MudRat_02
Very nice! Only problem here is that you press enter to start the game (and thus control the crosshair). Before I press enter, the crosshair is indeed moving in a nice smooth action, but as soon as I hit enter I once again have complete control of the crosshair. Any idea how to remedy this?
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 1:57 pm
by Bee-Ant
Actor1->KeyDown->Enter->ScriptEditor
- Code: Select all
start=1;
Actor1->DrawActor->ScriptEditor
- Code: Select all
if(start==1)
{
if(x<center.x)
{
xvelocity+=1;
}
if(x>center.x)
{
xvelocity-=1;
}
if(y<center.y)
{
yvelocity+=1;
}
if(y>center.y)
{
yvelocity-=1;
}
}
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 2:09 pm
by MudRat_02
I tried that, same result except the crosshair doesnt move at all before I hit enter now :S
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 2:16 pm
by Bee-Ant
That code works perfectly in my comp...it's weird
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 2:17 pm
by MudRat_02
must be something to do with the variable. Start is just a standard user-created variable right? I'm also controlling the crosshair by mouse, does that make a difference?
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 2:33 pm
by Bee-Ant
That's the problem...before you control it with mouse, put
- Code: Select all
if(start==1)
{
//mouse control
}
Re: Ricochet and Turbulence Effect
Posted:
Sun Feb 03, 2008 2:38 pm
by MudRat_02
Sry im confused - // is for notation, and apart from that its the same :S. Am i supposed to put that somewhere else?
Re: Ricochet and Turbulence Effect
Posted:
Mon Feb 04, 2008 7:58 am
by Bee-Ant
Oh...uh...ah...
How hard it's gonna be...
OK...I'll make a demo