Rotating entity continuously
Blitz3D Forums/Blitz3D Beginners Area/Rotating entity continuously
| ||
hey, new question involving the rotating of an entity. What I want, is to push a button and my entity to get moving and rotate with a push of a button, and not have to hold the button down while it's moving or turning. I've created 2 functions for this, however neither of them work, could you take a look and see what I'm doing wrong? should I put the keydowns in the main loop with the rest of my keyhits and keydowns? Should i move somethings around or not use functions at all? Thanks, Chad ; Vehicle controlls Function StearSub() ;Turn sub If KeyDown(27) ty#=ty#+2.1 ; Turn right Else If KeyDown(26) ty#=ty#-2.1 ; Turn left Else If KeyDown(40) ty#=0 ; Rudder midship End If ty#=ty#+1 RotateEntity conn,tx,ty,tz TurnEntity conn,tx,1,tz ; End Function ; Function to move the vehicle Function MoveSub() MoveEntity conn,mx,my,mz TurnEntity conn,tx,ty,tz End Function |
| ||
Do you mean something like this:repeat if keyhit(key used to turn left) then TurnLeftFlag=1-TurnLeftFlag:TurnRightFlag=0 if keyhit(key used to turn right) then TurnRightFlag=1-TurnRightFlag:TurnLeftFlag=0 if TurnLeftFlag<>0 then turnentity myentity,0,1,0 endif if TurnRightFlag<>0 then turnentity myentity,0,-1,0 endif updateworld renderworld flip until keydown(1) |
| ||
What I want, is to push a button and my entity to get moving and rotate with a push of a button, and not have to hold the button down while it's moving or turning. Then you need to initiate a variable to keep track of whether the object is supposed to be in motion/turning or not. EDIT: Here, I would be thinking along these lines... Cursor keys + space (to center rudder). |
| ||
Ok, I liked where Matty was going with his, and I changed some things around and I like the way it goes. But his was for the rudder only. I took a look at your code Sledge and kinda got confused when looking at the velocities and stuff. I've been trying for about an hour now to get my sub to move, I've tried moveentity and translateentity to no avail. I could be missing something pretty obvious, it's 3:05am in the morning here and pretty brain dead, so if I am just smack me in the back of the head and tell me nicely. I've commented out a lot thinking maybe I missed something somewhere later, so I left the two commands the same. I tried, keyhit, keydown, translateentity, moveentity, and yet my sub stays stationary. Please take a look and could you tell me why it isn't moving? ;SPEED SETTINGS If KeyDown(num1) Then Aheadslow=1-Aheadslow:Aheadtwothirds=0;:AheadStandard=0:AheadFull=0:AheadFlank=0 If KeyDown(num2) Then Aheadtwothirds=1-Aheadtwothirds:AheadSlow=0;:AheadStandard=0:AheadFull=0:AheadFlank=0 ;If KeyDown(num3) Then Aheadstandard=1-Aheadstandard:AheadSlow=0:Aheadtwothirds=0:AheadFull=0:AheadFlank=0 ;If KeyDown(num4) Then AheadFull=1-aheadFull:Aheadslow=0:Aheadtwothirds=0:AheadStandard=0:AheadFlank=0 ;If KeyDown(num5) Then aheadFlank=1-aheadFlank:Aheadslow=0:Aheadtwothirds=0:AheadStandard=0:AheadFull=0 If Aheadslow<>0 Then MoveEntity conn,.4,0,0 EndIf If Aheadtwothirds<>0 Then MoveEntity conn,2.0,0,0 EndIf ;If Aheadstandard<>0 Then ;TranslateEntity conn,7,0,0 ;EndIf ;If AheadFull<>0 Then ;TranslateEntity conn,12,0,0 ;EndIf ;If AheadFlank<>0 Then ;TranslateEntity conn,16,0,0 ;EndIf |
| ||
How are you moving your camera? It isn't parented to the sub or anything silly is it? Make sure your variables are global especially if you are using floating point numbers. Use text 0,0, entityx(conn) text 0,20,entityy(conn) text 0,40,entityz(conn) after renderworld to display sub co ordinates to make sure they are changing. IPete2. |
| ||
I found out what I did wrong.. Just a stupid mistake you make when your tired! |
| ||
Also, looks like you should be using Keyhit(0 instead of Keydown() :) |
| ||
Yeah, one of the things I changed.. I tell you, I was out of it =) Sleepiness can tear a project in half in an hour, and when your better it takes you 2 hours to fix what you did in the 1 hour. |
| ||
I totally agree with that. Never work on something after 12... unless you've had some red bull. :-P |
| ||
I totally agree with that. Never work on something after 12... unless you've had some red bull. Or didnt getup until Lunch |