Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / need help with a bit of maths

Author
Message
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 12th Jun 2003 22:43
Its not surprising i am about to fail A-Level maths. I cant figure it out. I need help making elite style movement, but only on the x and z plains. so far i have got a plain to move sort of how i want it to but there are still flaws and i cant seem to smoothe them out.

here's the code of what i have done so far.

The project has only just been started so there isnt much to see. Ive remed all the image commands as you wont have the pics.
He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 12th Jun 2003 23:09
here you are
my code is easy to understand, so I didn't use rem ^^I hope that I've done what you wanted to have

"He will come...the voice from the outer world,
bringing the holy war, the Jihad, which will cleanse the Universe and bring us out of darkness."
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 13th Jun 2003 00:36
Ive had similar to that on a previous attempt but i need a max speed. and if you point straight up then let go of up, rotate 90 deg then hold up again it moves up and across. I wanted it to slow the upwards motion whilst accelerating to the right. so that the plain will gradually change direction until moving the direction its pointing. Its one of those hard to explain things. I should have been a bit more specific on my first post, soz.

He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 14th Jun 2003 00:49
you mean like this:
gosub startup
gosub makearrays

make object plain 1,25,25
xrotate object 1,90
fix object pivot 1
position object 1,0,0,0
load image "ship.bmp",2
texture object 1,2
set object 1,1,1,1
fade object 1,200

load image "plasma2.bmp",3
make particles 1,3,5,10
set particle gravity 1,0
set particle floor 1,0
set particle life 1,15
set particle velocity 1,0

do


camera()
gosub movement

sync
loop

startup:

sync on
sync rate 60
autocam off
set display mode 1024,768,16
set camera view 50,0,1023,767
color backdrop 0

make matrix 1,1000,1000,10,10
position matrix 1,0,-10,0
return


makearrays:
return

movement:
if leftkey()=1 then yang#=wrapvalue(yang#-2)
if rightkey()=1 then yang#=wrapvalue(yang#+2)
yrotate object 1,yang#

xp#=object position x(1)
zp#=object position z(1)


if upkey()=1
thrust#=thrust#+0.05
else
if downkey()=1
thrust#=thrust#-0.05
rem else
rem thrust#=0
endif
endif

o#=newxvalue(0,yang#,thrust#)
a#=newzvalue(0,yang#,thrust#)

if yang#>180
o#=sqrt(o#*o#)*-1
else
o#=sqrt(o#*o#)
endif

if yang#>90
if yang#<270
a#=sqrt(a#*a#)*-1
endif
else
a#=sqrt(a#*a#)
endif

h#=sqrt(((x1#+o#)*(x1#+o#))+((z1#+a#)*(z1#+a#)))
if h#<1.5
x1#=x1#+o#
z1#=z1#+a#
endif

x#=xp#+x1#
z#=zp#+z1#

move object 1,thrust#
rem position object 1,x#,0,z#

px#=newxvalue(x#,wrapvalue(yang#+180),13)
pz#=newzvalue(z#,wrapvalue(yang#+180),13)

position particle emissions 1,px#/10,0,pz#/10


return





function camera()

x#=object position x(1)
z#=object position z(1)

position camera x#,200,z#
point camera x#,0,z#

endfunction
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 14th Jun 2003 01:07
It really is one of thse hard to explain things. my maths is sooo s**t at the moment that i cant do this. And to think im gonna do a physics degree.

Thanx but what u have done is made racecar movement with no speed limit. on elite you can turn and you wont instantly change direction. this is because of momentum, an it takes a while for the ship to change its velocity.

The idea is to eventually create a cross between elite and star control. Which i hope is a good combination. because of recent events with exams and programing i think i might change my career path to something a little easier.... like drinking, i dont need maths for that!

He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 14th Jun 2003 14:13
Well i know what you mean now..
here s an attempt done by delaying the angle adjustment between 2 objects
basically your ship and a hidden object that takes the full rotation right away (object 2) and the code slowly aligns the ship angle to that from the old y angle value..
It s not perfect because i have to compare magnitudes to angles and the 0-360 wrap range is not ideal for that,,so if the 2 angles differ more than much the spin will get reversed in direction..
For a perfect code i guess one should use real speed,velocity and momentum maths with vectors and thats beyond my reach as of now

code:

gosub startup
gosub makearrays

make object plain 1,25,25
xrotate object 1,90
fix object pivot 1
position object 1,0,0,0
load image "ship.bmp",2
texture object 1,2
set object 1,1,1,1
fade object 1,200

make object plain 2,25,25
xrotate object 2,90
fix object pivot 2
position object 2,0,0,0
rem remove rem to hide object 2
rem hide object 2

load image "plasma2.bmp",3
make particles 1,3,5,10
set particle gravity 1,0
set particle floor 1,0
set particle life 1,15
set particle velocity 1,0

do
camera()
gosub printdata
gosub movement
sync
loop

startup:
sync on
sync rate 60
autocam off
set display mode 800,600,16
set camera view 50,0,1023,767
color backdrop 0

make matrix 1,1000,1000,10,10
position matrix 1,0,-10,0
return

makearrays:
return

movement:
if upkey()=1 and thrust# < 4 then thrust#=thrust#+0.05
if downkey()=1 and thrust# > -4 then thrust#=thrust#-0.05
if leftkey()=1 then yang#=wrapvalue(yang#-2)
if rightkey()=1 then yang#=wrapvalue(yang#+2)
yrotate object 2,yang#
yang2#=object angle y(1)
diff#=yang#-yang2#
newangle#=yang#-diff#
if (yang#>270 and yang2#<90) or (yang#<90 and yang2#>270)
if diff#>0.8 then yrotate object 1,wrapvalue(newangle# - abs(thrust#/5))
if diff#<-0.8 then yrotate object 1,wrapvalue(newangle# + abs(thrust#/5))
else
if diff#>0.8 then yrotate object 1,wrapvalue(newangle# + abs(thrust#/5))
if diff#<-0.8 then yrotate object 1,wrapvalue(newangle# - abs(thrust#/5))
endif

x#=newxvalue(x#,yang#,thrust#)
z#=newzvalue(z#,yang#,thrust#)

position object 1,x#,0,z#
position object 2,x#,0,z#

px#=newxvalue(x#,wrapvalue(yang2#+180),13)
pz#=newzvalue(z#,wrapvalue(yang2#+180),13)
position particle emissions 1,px#/10,0,pz#/10
return

printdata:
set cursor 0,0
print "framerate=",screen fps()
print "x#=",x#
print "z#=",z#
print "thrust#=",thrust#
print "yang#=",yang#
print "yang2#=",yang2#
print "diff#=",diff#
print "newangle#=",newangle#
return

function camera()
x#=object position x(1)
z#=object position z(1)
position camera x#,200,z#
point camera x#,0,z#
endfunction
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 14th Jun 2003 17:42
thanks but that still isn't what i wanted. never mind. it needs a lot of thought.

heres another attempt at an explanation. If any of you has played star control then you will know what sort of movement i am looking for.

I want a ship to accelerate in the direction its facing only when the upkey is pressed.

I want to be able to set the max velocity.

it the ship is moving upwards and then you rotate it without any acceleration then it will still going upwards even tho its pointing in a different direction.

if the ship it going upwards and you rotate it so it points left, you then accelerate in the direction its facing and the upwards momentum that it had before will slowly go to whatever up speed it should have to be traveling in the direction it points in.

That last one is the tricky one. The trails are so you can see the direction of movement compared to the direction its facing.

I will try and do it after my exams i think. but thanks anyway for your help. Once i do it (if i do it) i will post it so you can see what it is i wanted. And you may want to use it yourself.

He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 15th Jun 2003 02:01
good luck for your exams

"He will come...the voice from the outer world,
bringing the holy war, the Jihad, which will cleanse the Universe and bring us out of darkness."
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 15th Jun 2003 17:40
this is hat i have come up with after your last explanation..
should be close to what you want..let me know

gosub startup
gosub makearrays

make object plain 1,25,25
xrotate object 1,90
fix object pivot 1
position object 1,0,0,0
load image "ship.bmp",2
texture object 1,2
set object 1,1,1,1
fade object 1,200

load image "plasma2.bmp",3
make particles 1,3,5,10
set particle gravity 1,0
set particle floor 1,0
set particle life 1,15
set particle velocity 1,0
yang#=0
yang1#=0.0

do
camera()
gosub printdata
gosub movement
sync
loop

startup:
sync on
sync rate 60
autocam off
set display mode 800,600,16
set camera view 50,0,1023,767
color backdrop 0

make matrix 1,1000,1000,10,10
position matrix 1,0,-10,0
return

makearrays:
return

movement:
if upkey()=1
thrust#=1
if speed#<1 then speed#=speed#+0.1
else
if downkey()=1
thrust#=-1
if speed#>-1 then speed#=speed#-0.1
else
thrust#=0
endif
endif

if leftkey()=1 then lflag=1:rflag=0:yang#=wrapvalue(yang#-2)
if rightkey()=1 then rflag=1:lflag=0:yang#=wrapvalue(yang#+2)

x#=newxvalue(x#,yang1#,speed#)
z#=newzvalue(z#,yang1#,speed#)
position object 1,x#,0,z#
yrotate object 1,yang#

if thrust#=1 and yang#<>yang1# and rflag=1
yang1#=wrapvalue(yang1#+1)
endif
if thrust#=1 and yang#<>yang1# and lflag=1
yang1#=wrapvalue(yang1#-1)
endif
if thrust#=-1 and yang#<>yang1# and rflag=1
yang1#=wrapvalue(yang1#+1)
endif
if thrust#=-1 and yang#<>yang1# and lflag=1
yang1#=wrapvalue(yang1#-1)
endif

px#=newxvalue(x#,wrapvalue(yang#+180),13)
pz#=newzvalue(z#,wrapvalue(yang#+180),13)
position particle emissions 1,px#/10,0,pz#/10
return

printdata:
set cursor 0,0
print "framerate=",screen fps()
print "x#=",x#
print "z#=",z#
print "thrust#=",thrust#
print "yang#=",yang#
print "yang1#=",yang1#
print "speed#=",speed#
return

function camera()
x#=object position x(1)
z#=object position z(1)
position camera x#,200,z#
point camera x#,0,z#
endfunction
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 15th Jun 2003 20:43
thanks almost perfect. It does this weird thing where it does a full circle when i push up when facing up from a stop. only sometimes tho. Im gonna study the code and see how youve done it.

Thanks again.

He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 15th Jun 2003 21:18
ive had a look at the code and done some testing. if you point up and accelerate, then do a 180 without any thrust so your pointing down, then thrust the ship doesnt just reverse direction it moves to the left or right and sort of curves round.im gonna try and sort it out.

He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 15th Jun 2003 22:48
i don t have time to refine it right now, but you could add some code that checks when abs(yang#-yang1#) > 180 and it forces the 2 angles to equal when thrust is given again..
( just a thought, not sure it will work)
Rye
23
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 16th Jun 2003 00:08
I am soooo happy. I managed to do it. I cant believe it was sooo simple.
Here it just so you know what i wanted. The games gonna be a multiplayer one coz i cant be arsed with AI. Loads of people want to make an elite clone and so i thought why not make a version without a y axis. its a lot simpler. i'm gonna cross it with star control, i hope its gonna work.please post any ideas for my game coz i wanna make it a good on.

gosub startup
gosub makearrays

make object plain 1,25,25
xrotate object 1,90
fix object pivot 1
position object 1,0,0,0
load image "ship.bmp",2
texture object 1,2
set object 1,1,1,1
fade object 1,200

load image "plasma2.bmp",3
make particles 1,3,5,10
set particle gravity 1,0
set particle floor 1,0
set particle life 1,15
set particle velocity 1,0
color particles 1,0,0,250

do

camera()
gosub movement

set cursor 0,0 : print screen fps()
sync
loop

startup:

sync on
sync rate 0
autocam off
set display mode 1024,768,16
`set camera view 50,0,1023,767
color backdrop 0

make matrix 1,1000,1000,10,10
load image "nebula.bmp",1
prepare matrix texture 1,1,1,1
ghost matrix on 1
position matrix 1,0,-10,0
return


makearrays:
return

movement:

px#=object position x(1)
pz#=object position z(1)

if upkey()=1
thrust#=2
x#=curvevalue(x#,sx#,1.01)
z#=curvevalue(z#,sz#,1.01)
else
thrust#=0
if downkey()=1
x#=curvevalue(x#,sx#,1.01)
z#=curvevalue(z#,sz#,1.01)
endif
endif

if leftkey()=1 then yang#=wrapvalue(yang#-2)
if rightkey()=1 then yang#=wrapvalue(yang#+2)
yrotate object 1,yang#

sx#=newxvalue(0,yang#,thrust#)
sz#=newzvalue(0,yang#,thrust#)

position object 1,px#+x#,0,pz#+z#


partx#=newxvalue(x#,wrapvalue(yang#+180),13)
partz#=newzvalue(z#,wrapvalue(yang#+180),13)
position particle emissions 1,partx#/10,0,partz#/10
rem the above /10 on the x and z positions is due to a problem with the positioning of particles
rem to get the right position you have to divide the wanted position by the particle radius.
return

function camera()

x#=object position x(1)
z#=object position z(1)

position camera x#,200,z#
point camera x#,0,z#

endfunction

He who keeps his work in disorder gives home to chaos. Let him be struck with stone and iron to forge away his flaws

Login to post a reply

Server time is: 2026-07-17 21:22:27
Your offset time is: 2026-07-17 21:22:27