Code for moving an object like an insect flying

Blitz3D Forums/Blitz3D Beginners Area/Code for moving an object like an insect flying

3DFish(Posted 2004) [#1]
Hey there

I'm designing an insect that will fly around
a character in my game.
The insect should fly around the character's head and annoys him constantly.
I'm still struggling with Blitz maths (Sin, Cos)

Are there some of you who could help me with the code?

Thanks


3DFish(Posted 2004) [#2]
Sorry..Forgot to mention.
The game is in a 3D environment.
So the insect should move on the x,y,z axis


big10p(Posted 2004) [#3]
Easiest way would probably be to place a pivot where your character's head is, parent the insect to the pivot and move it a suitable distance from the head. Then you can turn the pivot in whatever way you like to make the insect move around the head.


WolRon(Posted 2004) [#4]
Then you can turn the pivot in whatever way you like to make the insect move around the head.
However, this will also make the insect fly upside-down, backwards, sideways and whatever else as well as possibly flying through the players shoulders, neck.

A better way would probably be to just make the insect fly forwards and turn a slight but random amount (you will have to tweak how much) towards the players head every turn. It's OK if the insect doesn't turn fast enough and overshoots, because this will actually make it look more natural (as opposed to just flying around and around in circles). Of course, you will have to add a check in there (maybe a linepick straight ahead) to make sure that the insect doesn't fly straight through the players head.


semar(Posted 2004) [#5]
A simple but quite effective method (perhaps like big10p has though):

Graphics3D 640,480,0,2

AmbientLight 200,200,1

Global sphere = CreateSphere()
EntityAlpha sphere,0.9
PositionEntity sphere,0,0,20

cam = CreateCamera()
PositionEntity cam,0,10,0
PointEntity cam,sphere

Global pivot = CreatePivot(sphere)

Global fly = CreateSphere(12,pivot)
PositionEntity fly,5,0,0
EntityColor fly,255,0,100
sc# = 0.5
ScaleEntity fly,sc,sc,sc



While Not KeyDown(1)

TurnEntity pivot,Rand(-10,10),6,0

UpdateWorld
RenderWorld
Flip


Wend
End


Sergio.


big10p(Posted 2004) [#6]
Yes, that's the kind of thing I was talking about, Semar. ;)


However, this will also make the insect fly upside-down, backwards, sideways and whatever else as well as possibly flying through the players shoulders, neck.


Heh, I realize that. I was just suggesting the basic concept without getting bogged down with details. :)

Making the insect always stay upright is just a matter of adding 'RotateEntity insect,0,0,0,1' after turning the pivot.

There are ways to stop the insect flying through the character's shoulders, too. I guess you could just track the rotation of the pivot and make sure it can't pitch (or whatever) beyond a certain threshold.


3DFish(Posted 2004) [#7]
Thanks guys

Thanks for the code semar.

It works when I do a TurnEntity pivot with a smaller
random number.
TurnEntity pivot,Rand(-2,2),6,0

The chance of the fly moving through the player's head or shoulders, are now less.


Rook Zimbabwe(Posted 2004) [#8]
Keeping in mind that I am but a novice in B3d... I was told about parent and child... if your player is the parent then the bug would position itself in relation to the parent and rotate around him. I think Ross did a demo of this using P/C with a camera that rotated around the sun (or something)
-RZ