hovering a ship

Blitz3D Forums/Blitz3D Beginners Area/hovering a ship

Maximus Primal(Posted 2005) [#1]
Sorry for all the questions these last couple of days. I hope this will be the last one. It is the last fundimental thing I need to sort out.

I have now got the gravity and hill/slope problem from mylast post about 90% sorted out which is about as much as I can hope for at the moment.

I now need a guide on how to do something. I need my ship to float above the track but still interact with it. So rather than drive on it, it flys over it - maintaing the same height as it goes.

I have tried to add a pivot point below the ship but this does not appear to work or move correctly within the code I have. Is this the right idea or am I look at it the wrong way? I don't want code, just a suggestion on how to do it.

Thanks

Max


Bot Builder(Posted 2005) [#2]
In my tokamak hovercraft thing i effectivly did linepicks down, and used the distance to create impulses based on the distance.


Maximus Primal(Posted 2005) [#3]
Sorry you did what???

Max


Ross C(Posted 2005) [#4]
If you do a linepick straight down from your ship, you can find the distance from the ship to the ground directly below. Look at the linepick command in blitz3d :o) quite handy :o)


Maximus Primal(Posted 2005) [#5]
Right. Thanks, I thought it was a method if doing it - not an acutal command. I will take a look in a moment.


Maximus Primal(Posted 2005) [#6]
Okay, I have looked up the command and maybe I am having serious brain ache tonight but I cannot see how it works or how to use it as suggested.

Also it doesn't solve the hovering question in that my ship would still have to collide with the track to move up the hills, where as I want to make it hover above it and STILL move over the hills without crashing into them first...

If this command is the way can someone show me how as I really cannot see it...

Max


Bot Builder(Posted 2005) [#7]
depends on if you want it to be a semi realistic hovercraft or sci fi ish one. A real one would hover with maybe an inch between the skirt and the ground. Mine was sci fi, so it was kinda bouncy and floated about rather high.

Basically I did linepicks down from each corner of the craft, and took the inverse of the distance multiplied by a tweaked value. Then I applied this velocity negated to the corner I picked from. This essentially makes a nice bouncy hovercraft where if you tilt it'll start moving in the direction you tilt, while attempting to reorient upright.


Maximus Primal(Posted 2005) [#8]
Okay I think I understand that - just!

But the reference guide describes the command as "Returns the first entity between x,y,z to x+dx,y+dy,z+dz. ". How the hell do you measure with it then? I assume it is used like this: "result=linepicks 0,0,0,0,-100,0" In which case what would it return as a result?

The effect you desicribe is on par with what I would like to acheive (although my ship is not square/circular but that shouldn't make much difference from what I can tell). I still cannot see how this command would acheive that result.

Can you tell me how to use it to do this and give a line or two of code that explains the command as there is no example in the help file or online help :( I am still totaly lost with regards to this command...

Thanks

Max


Shambler(Posted 2005) [#9]
Once you have a result from the Linepick in PickedEntity() you can check

PickedX() PickedY() PickedZ() for the exact picked position
and
PickedNX() PickedNY() PickedNZ() for the normal of the picked triangle

Check out those commands and you should see the light.


Maximus Primal(Posted 2005) [#10]
I must be totaly stupid here. I have looked up the Pickedx() command and I STILL cannot figure it out.

I cannot make head nor tale of the example inlcuded with the PickedX() command, all I see is a set of apparently random numbers which bear no resembleance to any distances that I can use to make a ship hover. It does have the Linepick command in it so I cannot see how that fits into it either.

Sorry if I sound totaly dumb here, but I just cannot see how this works at all at the moment...

Max


Ross C(Posted 2005) [#11]
Well, you do a line pick straight down.

LinePick x,y,z,0,-10,0 ; make the line pick start from x,y,z, and go down 10 units on the z axis. [EDIT] STUPID MISTAKE FIXED

Now, you need to make the mesh you want to hover above PICKABLE, which means setting an "entitypickmode" for it. Or else the linepick won't collide with it.

Now, once you've done your line pick, check that PickedEntity <> 0 , meaning that something has actually been detected by the linepick.

Now, contained within PickedX(),PickedY() and Picked(Z), are the co-ords of where the collison occured. Your only looking for the height, so only PickedY() really concerns you. Simply subtract the PickedY() from the start co-ords of your LinePick, to get the height above the collision, your ship is.

Hope that helps you :o)


Maximus Primal(Posted 2005) [#12]
PERFECT!!!! Suddenly the fog clears and he sees what has been there all the time! :D :D :D

Thank you sooooo much for that. It now makes perfect sense how this works and how to do what I need to.

I cannot thank you enough! (Creep mode off)

Max


Maximus Primal(Posted 2005) [#13]
Oh boy.... My day doesn't get any better with this does it?

Okay this is what I added.

This was placed after the track is loaded and setup:
EntityPickMode track,2


This was added into the mainloop:
shipx=EntityX(ship)
shipy=EntityY(ship)
shipz=EntityZ(ship)

LinePick shipx,shipy,shipz,0,-50,0

	num=PickedEntity()
	tracky=PickedY()
	dist=shipy-tracky


I use this to monitor the values as I move the ship:
                Text 320,540,EntityY(ship)
	Text 450,540,PickedY()
	Text 600,540,dist


When I move the ship around I will get any thing from 1 to -100 (Even though the track is ALWAYS below the ship)!

I am starting to wonder if this was such a good idea now... :( :( :( I assume I have done something obviously wrong here (well I hope I have. If anyone can tell me what I really would appreicate it cause I am about as lost as a blind mouse in a giant maze ;(

Max


Stevie G(Posted 2005) [#14]
A couple of things .. make sure shipx,y & z are floats and also dist. If the ship is a child of something make sure you reference the global space position .. i.e. entityx( ship , true )


Ross C(Posted 2005) [#15]
Hey, i've knocked this together. Shows a basic example of what your wanting. Re-reading my post, you should add the height above the track you want the ship to be, to the pickedy(), to get the Y co-ord you want your ship to be at.

Graphics3D 800,600
SetBuffer BackBuffer()


Global cam = CreateCamera()

Global light = CreateLight()

Global ship = CreateCube()

Dim track(9); create a dummy track out of spheres
For loop = 0 To 9
	track(loop) = CreateSphere()
	ScaleEntity track(loop),3.5,4,10
	PositionEntity track(loop),-20+loop*5,0,0
	EntityPickMode track(loop),2
Next

PositionEntity cam,0,0,-20
PositionEntity ship,0,5,0

Global dist_above_track# = 3


While Not KeyHit(1)


	If KeyDown(203) Then MoveEntity ship,-0.1,0,0
	If KeyDown(205) Then MoveEntity ship,0.1,0,0


	x# = EntityX(ship,True)
	y# = EntityY(ship,True)
	z# = EntityZ(ship,True)
	
	LinePick x,y,z,0,-10,0 ; perform the line pick
	
	If PickedEntity() <> 0 Then ; make sure an entity has been picked
		PositionEntity ship,x,PickedY()+ dist_above_track,z ; place the ship above the pickedy() co-ord
	End If



	UpdateWorld
	RenderWorld
	Text 0,0,(PickedY()+ dist_above_track)
	Flip
Wend
End 



Ross C(Posted 2005) [#16]
Here's another example with using the normals of the line pick to align the ship to the angle of the slope. A bit jitter because of the sharp angle change between each cylinder, but illustrates the point :o)

Graphics3D 800,600
SetBuffer BackBuffer()


Global cam = CreateCamera()

Global light = CreateLight()

Global ship = CreateCube()

Dim track(9); create a dummy track out of spheres
For loop = 0 To 9
	track(loop) = CreateCylinder(40)
	ScaleEntity track(loop),3,10,2
	RotateEntity track(loop),90,0,0
	PositionEntity track(loop),-20+loop*5,0,0
	EntityPickMode track(loop),2
Next

PositionEntity cam,0,4,-20
PositionEntity ship,0,5,0

Global dist_above_track# = 3


While Not KeyHit(1)


	If KeyDown(203) Then MoveEntity ship,-0.1,0,0
	If KeyDown(205) Then MoveEntity ship,0.1,0,0


	x# = EntityX(ship,True)
	y# = EntityY(ship,True)
	z# = EntityZ(ship,True)
	
	LinePick x,y,z,0,-10,0 ; perform the line pick
	
	If PickedEntity() <> 0 Then ; make sure an entity has been picked
		PositionEntity ship,x,PickedY()+ dist_above_track,z ; place the ship above the pickedy() co-ord
		AlignToVector ship,PickedNX(),PickedNY(),PickedNZ(),2,0.5
	End If



	UpdateWorld
	RenderWorld
	Text 0,0,(PickedY()+ dist_above_track)
	Flip
Wend
End



Rook Zimbabwe(Posted 2005) [#17]
Excellent examples... I have been playing with an off road rally and just started the linepicks your method is simpler than mine (y'all know how I like to pass variables around!)
RZ


Maximus Primal(Posted 2005) [#18]
Thanks, now I can see where I have gone wrong. That is most kind to post that.

Max


Maximus Primal(Posted 2005) [#19]
Okay here is a thought now. I now have got my ship to hover correctly :) For which I am VERY greatful. But now the gravity function that was in place that helped my ship fall gently to the ground after leaving a hill doesn't work :(

I tried this:

sx#=EntityX(ship,True)
sy#=EntityY(ship,True)
sz#=EntityZ(Ship,True)

LinePick sx,sy,sz,0,-20,0

If PickedEntity()<>0
	If sy<=dist_above_ground Then
		PositionEntity ship,sx,PickedY()+dist_above_track,sz
		AlignToVector ship,PickedNX(),PickedNY(),PickedNZ(),2,0.5
	EndIf
EndIf

	realspeed=speed/10
	MoveEntity ship,0,0,realspeed
	TranslateEntity ship,0,GRAVITY,0


But now while the gravity works and the aligning to the shape of the track works, the ship is once again in the middle of the track and flying through it :( :( :( Why is this? I am assuming that the gravity always tries to land the object to 0 height and not 10 (as the dist_above_ground is set to).

How do I sort this out? I thought the If-Then statement would solve that. Sorry, this will hopefully be the last question for a while...

Max


Rook Zimbabwe(Posted 2005) [#20]
You are looking at the wrong variable change "sy" to PickedY() like this:

If PickedEntity()<>0
	If PickedY() < = dist_above_ground Then
		PositionEntity ship,sx,PickedY()+dist_above_track,sz
		AlignToVector ship,PickedNX(),PickedNY(),PickedNZ(),2,0.5
	EndIf
EndIf

I think... should work... anyone else care to pundit?