corkscrew like movement
BlitzMax Forums/MiniB3D Module/corkscrew like movement
| ||
I'm trying to work out how to make some of my enemies corkscrew towards the player, but i'm not having much luck. Basically the enemy should spin around it's x axis, and also face the player by turning around it's z axis (think top down). I'm guessing there is some fancy maths involved, but i'm not totally sure what it would be called, or where to start. Has anyone got any idea of how i can do this? Cheers Charlie |
| ||
So basically what you are talking about is spiraling? thats a traveling circle... so the enemy ship is going in a circle (x sin / y cos) while moving along the z axis |
| ||
No, the enemy moves along its x axis, and turns around it's z axis. think of the asteroids ship, where velocity is added to the x axis to move it forward, and it is rotated around the z axis. I've got that movement working just fine, but for some enemies i want it to appear as if they are spiraling towards the player, purely cosmetically. i don't want to interfere with the way they are moving towards the player, i just want then to spin around the x axis. My rather simple code at the moment is something like this: rotateentity entity,0,0,angle moveentity entity,speed,0,0 changing the x parameter in rotate entity just causes it to wobble in a strange way, so i'm assuming that i probably need to change the way i'm rotating. Cheers Charlie |
| ||
Do you mean the ship is spinning going toward the player? or actually flying in a spiral pattern as seen from the players view? Two ways to accomplish that... vector based movement as a ship would truly have in space.. like sliding. Then you would have to figure out what direction to face the ship with trusters on to spiral the ship... that would be complex... or the ship movement would have to be calculated (not thrust based), moved, and then the ship pointed at the player(ish). |
| ||
Maybe you could use a pivot, and attach the ship to the pivot? Then the ship can freely move, whilst the pivot is pointed at the player. Another idea would be, using translateentity. This is out of my head and might not work properly, but something along the lines of this: 'vector from ship to player rx# = entityx(player,1) - entityx(ship,1) ry# = entityy(player,1) - entityy(ship,1) rz# = entityz(player,1) - entityz(ship,1) 'normalize dd# = sqr(rx*rx+ry*ry+rz*rz) if dd = 0 then dd = 1 translateentity ship, rx/dd, ry/dd, rz/dd turnentity ship, sin(millisecs()*0.05), 0, 1 |
| ||
Yes, just spinning toward the player, not actually spiraling. My game is a 2d top down shooter, so i don't need the enemies to be going in or out of the screen, just pointing one way and spinning the other. I'll have a look at that code Warner, thanks. Cheers Charlie |
| ||
That code didn't help. I'm sure this isn't too difficult, maybe i'm not explaining it very well? here is some code: Import sidesign.minib3d Strict Local width=640,height=480,depth=16,mode=0 Graphics3D width,height,depth,mode Local cam:TCamera=CreateCamera() PositionEntity cam,0,0,-10 Local light:TLight=CreateLight() positionentity light,0,0,-10 Local cube:tmesh=createcube() Local ang:Int=1 While Not KeyDown(KEY_ESCAPE) ang:+1 rotateentity cube,ang,0,0 RenderWorld Flip Wend End In this sample the cube is rolling on the x axis. You can only ever see the sides of the cube as it its rolling, not the ends of the cube. if i rotate the cube around the z axis (by changing the 0 in the rotateentity command to something else, either constant or variable) as well as the x axis, i end up being able to see the ends of the cube (i.e it starts to wobble), which i don't want. How can i do this so it doesn't appear to be wobbling? Cheers Charlie |
| ||
Ok, i've been looking into this some more. I tried converting some of the car wheel examples in the code archives as that is the kind of movement i want (spinning wheels at any given direction). However they all use something like rotateentity (entity,spin,direction,0), which just makes things wobble in minib3d. Presumably the rotation code is different in minib3d and b3d? Cheers Charlie |
| ||
Shouldn't you be using TurnEntity, and not RotateEntity? |
| ||
Maybe you could look at my archive entry? http://www.blitzmax.com/codearcs/codearcs.php?code=2498 |