Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Movement Problems  (Read 1056 times)
birvin
Community Member
*
Posts: 52


« on: October 19, 2007, 11:11:40 PM »

Ok heres the problem i can get my ship to for foward back up down side to side with no problem.  My problem is when i point the ship in a particular heading i want it to go in that direction.  I have looked at many examples that came with truevision.  Heres my code.

    Public Sub ShipPosUpDate()
        'ShipPos.x = ShipPos.x + ShipSP * 0.01
        ShipPos.y = ShipPos.y + ShipThru * 0.01
        'ShipPos.z = ShipPos.z + ShipFP * 0.01
        ShipPos.x = ShipPos.x + System.Math.Cos(ShipHead) * ShipFP * 0.01
        ShipPos.z = ShipPos.z + System.Math.Sin(ShipHead) * ShipFP * 0.01
        ShipM.RotateY(ShipHead * 0.01, True)
        If ShipPos.y <> -34 And ShipPos.y > -34 Then
            ShipPos.y = ShipPos.y - 1 * 0.01
        ElseIf ShipPos.y = -34 Then
            ShipPos.y = -34
        End If

        ShipM.SetPosition(ShipPos.x, ShipPos.y, ShipPos.z)
    End Sub

when i rotate the ship it kinda does go in that direction but if i hold down the keys that change the angle of the ship it is all jerky and stops goin in the right direction. 
Logged
newborn
Customers
Community Member
*****
Posts: 2434


WWW
« Reply #1 on: October 19, 2007, 11:45:27 PM »

simply use meshShip.MoveRelative, its gonna save you tons of time and headaches.
Logged

birvin
Community Member
*
Posts: 52


« Reply #2 on: October 19, 2007, 11:49:41 PM »

ok ill try it
Logged
birvin
Community Member
*
Posts: 52


« Reply #3 on: October 19, 2007, 11:55:20 PM »

well when i use that the ships mesh is no longer there
Logged
nateslunaXX
Community Member
*
Posts: 229

Be cool..! Study Hard...


« Reply #4 on: October 20, 2007, 12:51:37 AM »

why don't you use newton physics to move your ship..just addimpulse towards the direction vector...which you don't have to calculate. there is this .getBasisVectors method..
Logged


Nathan Alcon, BSIT - Life is a never ending Cycle of Learning
birvin
Community Member
*
Posts: 52


« Reply #5 on: October 20, 2007, 10:47:12 PM »

i realy wana figure out why this aint working ive copied the bit of code that i thought was what made the particular thing move in the direction it is oriented.  is there some forumala that people use to get the amount of movement in the x,z cords based on a particular angle cause im a bit rusty on my algebra and geomety.  im gonna go in search for a book that has the mathmatics for game programming anf maybe even physics.
Logged
ovek
Community Member
*
Posts: 383


« Reply #6 on: October 21, 2007, 07:16:31 AM »

birvin this will make you go forward or backward based on your heading/direction/angle whatever you want to call it:

Code:
If TVInputEngine.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_UPARROW) Then
MyActorPosition.x = MyActorPosition.x - TVEngine.TimeElapsed * Math.Sin(MyActorAngle) * 0.03
MyActorPosition.z = MyActorPosition.z - TVEngine.TimeElapsed * Math.Cos(MyActorAngle) * 0.03
End If
If TVInputEngine.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_DOWNARROW) Then
MyActorPosition.x = MyActorPosition.x + TVEngine.TimeElapsed * Math.Sin(MyActorAngle) * 0.03
MyActorPosition.z = MyActorPosition.z + TVEngine.TimeElapsed * Math.Cos(MyActorAngle) * 0.03
End If

and use myactorangle to base your angle like so:

Code:
If TVInputEngine.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_LEFTARROW) Then
MyActorAngle = MyActorAngle - TVEngine.TimeElapsed * 0.003
End If
If TVInputEngine.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_RIGHTARROW) Then
MyActorAngle = MyActorAngle + TVEngine.TimeElapsed * 0.003
End If
Logged
birvin
Community Member
*
Posts: 52


« Reply #7 on: October 21, 2007, 09:12:48 AM »

thanks i figured it had some cos sin stuff in it ill try it later
Logged
birvin
Community Member
*
Posts: 52


« Reply #8 on: October 21, 2007, 01:00:07 PM »

what is the 0.03 at the end is that the number for the speed?
Logged
ovek
Community Member
*
Posts: 383


« Reply #9 on: October 21, 2007, 01:23:43 PM »

yea
Logged
birvin
Community Member
*
Posts: 52


« Reply #10 on: October 22, 2007, 04:41:20 PM »

thanks dude
Logged
Arakiel
Community Member
*
Posts: 26


« Reply #11 on: June 08, 2008, 09:33:38 PM »

Slight thread resurrection here but I registered for the forums simply to post a thank you to newborn for this simple, yet oh so helpful 1 liner.

simply use meshShip.MoveRelative, its gonna save you tons of time and headaches.

I had spent 3 hours trying to work out some similar movement code and failing (my math-fu is weak) and looked all over the place trying to find a sample of something similar before I finally stumbled upon this thread...and replaced 14 lines of non-working crud with 1 oh so beautiful line.  You've just made my night...granted you posted it 8 months ago but here is at least one belated thank you!

-Arakiel
Logged
newborn
Customers
Community Member
*****
Posts: 2434


WWW
« Reply #12 on: June 09, 2008, 06:01:45 AM »

Welcome to the boards!

I'm glad it helped at least 1 person!

Feel free to ask (intelligent questions) and we shall answer (if we know the answer).  Grin
Logged

jviper
Community Member
*
Posts: 1321

Discipline in training


« Reply #13 on: June 09, 2008, 12:50:53 PM »

Code:
Public Sub ShipPosUpDate()
        'ShipPos.x = ShipPos.x + ShipSP * 0.01
        ShipPos.y = ShipPos.y + ShipThru * 0.01
        'ShipPos.z = ShipPos.z + ShipFP * 0.01
        ShipPos.x = ShipPos.x + System.Math.Cos(ShipHead) * ShipFP * 0.01
        ShipPos.z = ShipPos.z + System.Math.Sin(ShipHead) * ShipFP * 0.01
        ShipM.RotateY(ShipHead * 0.01, True)
        If ShipPos.y <> -34 And ShipPos.y > -34 Then
            ShipPos.y = ShipPos.y - 1 * 0.01
        ElseIf ShipPos.y = -34 Then
            ShipPos.y = -34
        End If

        ShipM.SetPosition(ShipPos.x, ShipPos.y, ShipPos.z)
    End Sub

Sorry to be flagrant here, but this code is not right. The correct code should be:

Code:
ShipPos = ShipPos + (Speed*0.01)*ShipM.GetDirection()

This will always move your mesh in the ship's direction. This is actually what the MoveRelative function does. But the MoveRelative function will cause a blow up (mesh disapears or acts completly wild) if your mesh's direction is (0,0,0). It will also blow up if any of your scale components are 0, that is (scale.x = 0 or scale.y = 0 or scale.z = 0). The above code will simply will not move if any of that is true.

...and it seems alot of ppl seem to think alot of things require trignometric functions. It this case it could, but it does not have to. And if you do use them, you have to consider how to use them. I may have to post a new thread about it if it becomes an epidemic.
Logged

JAbstract.....Don't just imagine, make it happen!
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks