Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Space Game (https://forums.graalonline.com/forums/showthread.php?t=28116)

Er1c 04-27-2002 11:06 AM

Space Game
 
1 Attachment(s)
I am planning on making a completely space-based game (like Cosmic Rift or Starship Troopers (Cosmic Rift is going P2P and Starship Troopers went out of business)), but I really can't think of a way to make the movement work correctly with my limited math knowledge. I'll attach a level with what I have of the movement system so far, and also paste the code below.

NPC Code:
//#CLIENTSIDE
if (created) {
disabledefmovement;
showstats 0;
this.speed = 0;
this.dir = 0;
}
if (playerenters || timeout) {
//all
PI = 3.1415926535897932384626433832795;
this.rotatespeed = 0.1;
//normal
this.maxspeed = 1;
this.thrustspeed = 0.05;
this.turnspeed = 0.07;
//hyper
this.hypermaxspeed = 1.3;
this.hyperthrustspeed = 0.1;
this.hyperturnspeed = 0.02;

if (keydown(1))
this.dir = (this.dir+this.rotatespeed)%(PI*2);
if (keydown(3))
this.dir = (this.dir-this.rotatespeed)%(PI*2);

if (keydown(0) || keydown(2)) {
newspeed = this.speed+this.thrustspeed*(keydown(0)-keydown(2));
if (newspeed in <this.maxspeed*-1,this.maxspeed>) {
this.speed = newspeed;
}
this.angle = this.dir;
}
playerx += sin(this.angle)*this.speed;
playery += cos(this.angle)*this.speed;
for (i = 0;i<3;i++) {
showimg 200+i,@tempus sans itc@c@.,playerx+sin(this.dir)*(i*2),playery+cos(th is.dir)*(i*2);
changeimgcolors 200+i,0,0,2,.99;
changeimgvis 200+i,3;
}
temp();
timeout = .05;
}
function temp() {
if (keydown(5)) this.dir = (this.dir+PI)%(PI*2);
showimg 0,@#v(sin(this.angle)),10,50;
showimg 1,@#v(sin(this.dir)),10,70;
showimg 2,@#v(cos(this.angle)),10,90;
showimg 3,@#v(cos(this.dir)),10,110;
for (i = 0;i<50;i++)
changeimgvis i,4;
}


RavenTelvecho 04-27-2002 08:57 PM

looks neat but i dont know what it does lol
feels like a plane

Gohan43331 04-28-2002 04:55 AM

Wow...looks awsome...

Not sure what you mean by moving "correctly"... Seems to work pretty well for me...

Gohan43331 04-28-2002 09:01 AM

Ah, i see what you mean now...where you can change direction instantly...

Kadar 04-28-2002 11:18 AM

Quote:

Originally posted by Gohan43331
Ah, i see what you mean now...where you can change direction instantly...
No.
Go play cosmic rift and u will see :)
Its hard to explain.

prozac424242 05-01-2002 09:22 AM

cool
 
very nice, now to jsut add a ship image sprite rotaded liek every 5 degrees and a changeimgpart and have it work in mulitple levels... heh i like to hold right and up to fly in circles heh

adam 05-01-2002 12:58 PM

Perhaps I should try my hand at the Asteroids game I was working on again.


I felt it was quite nice. Especially since I had never had trig.
But im in trig class now.
We did vectors last week. :cool: Me likes.

And I finally understand the proper use of arcTan
I loves it. Very useful. I recall seeing it used and being baffled.
I am now knowing how to be using it.

adam 05-01-2002 01:17 PM

Anytime you need an angle =/ arctan is there. I didn't even know it returned an angle until a few weeks ago.


It's been a while but I remember wanting to figure out an angle and not knowing exactly how I was gonna do that. I prabably did way more than I needed to. arcTan would make it faster.

adam 05-01-2002 01:21 PM

Well say you wanted to make a compas for some odd reason? =/

Trivial things I guess. Hey it could happen.
I remember somebody once saying something like.
"You almost never need to use arrays"
hah. what a statement.

adam 05-01-2002 02:11 PM

=/ Ok so Im just crazy. gimmie a break.
We can live without angles I guess.

adam 05-02-2002 03:06 AM

Quote:

Originally posted by Kaimetsu
Actually, you're kinda right. I just realised that Graal's rotation function uses angles instead of transformation matrices. I suppose Stefan wanted to make it easier for us kiddies :-/
Graal has a rotation function?
What is a transformation matrices. haha. I know graphing my transformation and I kinda know finding determinants with matrices. but that it.

Er1c 05-02-2002 10:27 AM

Quote:

Originally posted by Kaimetsu
The movement is dependent on the heading rather than the general velocity. Maybe I should just fix it to show you.
Could you please? It's really just this part that needs to be fixed (well, more like changed... it's not broken, but it isn't working how I want):
NPC Code:
    newspeed = this.speed+this.thrustspeed*(keydown(0)-keydown(2));
if (newspeed in <this.maxspeed*-1,this.maxspeed> ) {
this.speed = newspeed;
}
this.angle = this.dir;


this.speed would be the velocity, and this.angle should be the heading. The heading should be determined by the direction and the velocity... but I'm not into math enough to do this.

I have done something like this, but instead of using a direction, I just had a x and y speed, which would be added to as keys were held, but using angles would make other things work much more efficently -- so, if someone (*looks at Kaimetsu*, lol) can help me out here, please do.

BocoC 05-02-2002 11:45 AM

Quote:

Originally posted by adam


Graal has a rotation function?
What is a transformation matrices. haha. I know graphing my transformation and I kinda know finding determinants with matrices. but that it.

Transformation matrices are mainly used in 3D Programming, like with Direct3D. I wouldn't worry about them if I were you.

Slaktmaster 05-02-2002 01:09 PM

newx = x+sin(angle)*velocity;

Could that work?

adam 05-03-2002 04:33 AM

Quote:

Originally posted by Kaimetsu


<DELETED ALL PROOFS>


Silly Kai. he was answering a question for me. Dun worry bout it.

Saga2001 05-03-2002 04:49 AM

Quote:

Originally posted by Kaimetsu


<DELETED ALL PROOFS>

I am pretty sure he wasn't talking to you...:cool:

Er1c 05-03-2002 07:34 AM

Quote:

Originally posted by Slaktmaster
newx = x+sin(angle)*velocity;

Could that work?

That would be for moving the player, not changing the velocity/angle in a space-like way.

Er1c 05-03-2002 10:57 PM

Quote:

Originally posted by Kaimetsu


<DELETED ALL PROOFS>

lmao

Well, anyway, could you help me out here with the equations for changing the velocity/speed and the angle you are traveling in? I really have no clue what I should do...

Sir_Gareth 05-04-2002 05:38 AM

UnholyNation has a space game

Frolic_RC2 05-04-2002 06:42 AM

1 Attachment(s)
Hmm...heres a script a long while ago.

It needs a TON of optimization, at least in ship movement, but I think it should be useful to you...

Especially the coolness nebula effects...

WARNING:
DUE TO THE NUMBER OF LIGHT EFFECTS, AND THE QUALITY OF MY COMP, THIS MAY LAG ON SOME OLDER COMPS. YOU HAVE BEEN WARNED.

adam 05-04-2002 09:47 AM

Quote:

Originally posted by Kaimetsu


Okiedokie.

Maintain an (dx,dy) for your current velocity. Add to it when you use the thruster in a given direction (dx+accel*cos(ang),dy+accel*sin(ang)) and limit the total speed with a unit vector. Ie:

mag=(dx^2+dy^2)^0.5;
if(mag>maxspeed){
dx=maxspeed*dx/mag;
dy=maxspeed*dy/mag;
}

:D :D I learned about vectors and unit vectors in school last week :D :D

But I like your explanation kai this is very useful.

Er1c 05-06-2002 02:59 AM

Quote:

Originally posted by Kaimetsu
Maintain an (dx,dy) for your current velocity. Add to it when you use the thruster in a given direction (dx+accel*cos(ang),dy+accel*sin(ang)) and limit the total speed with a unit vector. Ie:

mag=(dx^2+dy^2)^0.5;
if(mag>maxspeed){
dx=maxspeed*dx/mag;
dy=maxspeed*dy/mag;
}

Isn't there a way I could do this without saving a dx/dy and just saving the angle you're traveling in and the speed?

Er1c 05-06-2002 07:51 AM

Using angles would make everything else much easier, like shooting projectiles, onwall stuff, upgrades for the ships (like rotation speed upgrades or something), and then I could use the mouse to change the angle for a secondary way to move.

BUT, if it's too hard I'll just use the two velocity variables...

Er1c 05-06-2002 08:14 AM

If I use a vector I wouldn't need the angle... I'll just use the vectors, heh.

Thanks for you're help, Kaimetsu :)


All times are GMT +2. The time now is 06:58 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.