Welcome to Phrogram Sign in | Join | Help
in Search


Functionality/Feature Request - Postition(s) Relative to a 3D Object

Last post 03-06-2008, 7:42 AM by ZMan. 20 replies.
Page 1 of 2 (21 items)   1 2 Next >
Sort Posts: Previous Next
  •  03-27-2007, 2:58 PM 3384

    Functionality/Feature Request - Postition(s) Relative to a 3D Object

    Recently, I saw the Star Wars movies episodes 1 through 3. The battle sequences reminded me of the Star Wars video game, so I tried to achieve the same tank-driving functionality seen in it. It flopped. Here's what I tried to do:

    The tanks in Star Wars hover above the ground, giving them an all-terrain driving technique. I thought I could get the same effect by doing such:

    1. Most importantly, I need some detection method that can "feel" when the front, back, left or right sides of the tank encounter an incline, and tilt  the tank accordingly.
    2. A method that supplies momentum, so that the movement is more realistic.
    The momentum is not very high on my agenda. The real problem is the "incline sensors". I tried a point3D, but I can't position it relative to the tank/ship. Same goes for a Model3D. How might I reach my goal? How can I position a point/model relative to the ship? Thanks.
  •  03-27-2007, 5:15 PM 3385 in reply to 3384

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    you might try ship.translatePoint(0,0,0)  this creates a point3d that is relative to the model3D.  TranslatePoint(0,0,0)  the three values are x,y,z, you put how far away you want the object in those parameters. 

    for instance

    define shipFrontBumper  as point3d

    define shipRightBumper as point3d

    define shipLeftBumper as point3d

    define shipRearBumper as point3d

    define frontBumper as model3d

    define rightBumper as model3d

    define leftBumper as model3d

    define rearBumper as model3d

    define gameOver as boolean = false

     

    while gameOver = false

        shipFrontBumper = ship.translatePoint(0,0,5) will create a point 5 in front of the ship.

        shipRightBumper = ship.translatePoint(5,0,0) will create a point 5 to the ships right.

        shipLeftBumper = ship.translatePoint(-5,0,0) will create a point 5 to the ships left.

        shipRearBumper = ship.translaetPoint(0,0,-5) will create a point 5 behind ship.

     

         frontBumper.location = shipFrontBumper.location

        rightBumper.location = shipRightBumper.location

        leftBumper.location = shipLeftBumper.location

        rearBumper.location = shipRearBumper.location

     

    end while

     

    momentum will be more difficult(for me anyway) as it has to do with physics, you might try looking at SpringyThingy.kpl under the physics section in math programs.  This is a very complex program so good luck, but i think it has what your looking for, when ever the balls in the program break from the frame the continue with their own momentum.
     

     

     

  •  03-27-2007, 7:17 PM 3387 in reply to 3385

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    Thank you so much! I thought there was some method that would do that, but I couldn't find it. You saved my day!
  •  03-27-2007, 8:17 PM 3389 in reply to 3387

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    your welcome, thats what forums are for, if you get a momentum class or method working please post it so we can see an example of what you have, because i would really like to see a simpler example than SpringyThingy.kpl. 
  •  04-05-2007, 1:50 PM 3494 in reply to 3389

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    Here is the code I have so far. The collisions are not working properly:

     

     Program HoverShip
       
         Define ground As Model3D
        Define ship As Model3D
        Define cam As Camera
        Define sky As Skybox3D
       
        Define front As point3D
        Define left As point3D
        Define back As point3D
        Define right As point3D
        Define mid As Point3D
       
        Define f As Model3D
        Define l As Model3D
        Define b As Model3D
        Define r As Model3D
        Define m As Model3D
       
        Define loopy As Boolean = True
        Define speed As Decimal = 0.5
       
        Define ramp As Model3D
       
        Method Main()
       
            maximize()
            switchTo3D()

            LoadAll()
           
            While Not iskeydown( escape )
                cam.PointAtModel( ship )
                cam.Follow( ship, 5, 2 )
               
                drive()
                adjustShip()
                If mouse.MouseWheel > 0 Then
                    cam.Forward( mouse.MouseWheel )
                Else If mouse.MouseWheel < 0 Then
                    cam.Back( 1 )
                End If
                renderframe()
            End While
           
        End Method
       
        Method LoadAll()
           
            cam.MoveTo( 50,50,50 )
            cam.PointAt( 0,0,0 )
           
            ground.LoadMesh( "face2h.x" )
            ground.static = True
            ground.Scale( 50, 00, 50 )
           
            ship.LoadMesh( "fighter.x" )
            ship.MoveTo( 0, 3, 0 )
            ship.Scale( .1,.1,.1 )
           
            f.LoadMesh( "sphere.x" )
            b.LoadMesh( "sphere.x" )
            r.LoadMesh( "sphere.x" )
            l.LoadMesh( "sphere.x" )
            m.LoadMesh( "sphere.x" )
           
            //f.Scale( .2,.2,.2 )
            //b.Scale( .2,.2,.2 )
            //r.Scale( .2,.2,.2 )
            //l.Scale( .2,.2,.2 )
            //m.Scale( .2,.2,.2 )
           
            f.AddCategory( "1" )
            b.AddCategory( "2" )
            r.AddCategory("3")
            l.AddCategory("4")
            m.AddCategory("5")
           
            ramp.LoadMesh( "face2h.x" )
            ramp.Scale( 20,5,20 )
            ramp.MoveTo( 30, 2, 0 )
            ramp.TiltUp( 3 )
            ramp.EnableCollisions( "1" )
            ramp.Static = True
            ramp.AddCategory( "obstacle" )
           
            sky.LoadMesh( "skybox10.x" )
           
            f.EnableCollisions( "obstacle" )
           
        End Method
       
        Method Drive()
           
            front = ship.translatePoint(0, -10, 30 )
            back = ship.translatePoint(0, -10, -15 )
            right = ship.translatePoint(20, -10, 0 )
            left = ship.translatePoint(-20, -10, 0 )
            mid = ship.TranslatePoint(0, -11, 0 )
           
            f.Location = front
            b.Location = back
            r.Location = right
            l.Location = left
            m.Location = mid
           
            If iskeydown("up") Then
                ship.Forward( speed )
            End If
           
            If iskeydown("down") Then
                ship.Back( speed )
            End If
           
            If iskeydown("Right") Then
               
                ship.TurnRight( speed / 10 )
            End If
           
            If iskeydown("left") Then
               
                ship.TurnLeft( speed / 10 )
            End If
           
            If iskeydown(space) Then
               
            End If
           
            If iskeydown(shift) Then
                speed = speed + .2
            End If
           
        End Method
       
        Method AdjustShip()
            If f.HasCollision( ramp ) Then
                ship.TiltUp( 100 )
                ship.Back( speed )
            End If
        End Method
       
    End Program

     

     

  •  04-05-2007, 1:51 PM 3495 in reply to 3389

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    Here is the code I have so far. The collisions are not working properly:

     

     Program HoverShip
       
         Define ground As Model3D
        Define ship As Model3D
        Define cam As Camera
        Define sky As Skybox3D
       
        Define front As point3D
        Define left As point3D
        Define back As point3D
        Define right As point3D
        Define mid As Point3D
       
        Define f As Model3D
        Define l As Model3D
        Define b As Model3D
        Define r As Model3D
        Define m As Model3D
       
        Define loopy As Boolean = True
        Define speed As Decimal = 0.5
       
        Define ramp As Model3D
       
        Method Main()
       
            maximize()
            switchTo3D()

            LoadAll()
           
            While Not iskeydown( escape )
                cam.PointAtModel( ship )
                cam.Follow( ship, 5, 2 )
               
                drive()
                adjustShip()
                If mouse.MouseWheel > 0 Then
                    cam.Forward( mouse.MouseWheel )
                Else If mouse.MouseWheel < 0 Then
                    cam.Back( 1 )
                End If
                renderframe()
            End While
           
        End Method
       
        Method LoadAll()
           
            cam.MoveTo( 50,50,50 )
            cam.PointAt( 0,0,0 )
           
            ground.LoadMesh( "face2h.x" )
            ground.static = True
            ground.Scale( 50, 00, 50 )
           
            ship.LoadMesh( "fighter.x" )
            ship.MoveTo( 0, 3, 0 )
            ship.Scale( .1,.1,.1 )
           
            f.LoadMesh( "sphere.x" )
            b.LoadMesh( "sphere.x" )
            r.LoadMesh( "sphere.x" )
            l.LoadMesh( "sphere.x" )
            m.LoadMesh( "sphere.x" )
           
            //f.Scale( .2,.2,.2 )
            //b.Scale( .2,.2,.2 )
            //r.Scale( .2,.2,.2 )
            //l.Scale( .2,.2,.2 )
            //m.Scale( .2,.2,.2 )
           
            f.AddCategory( "1" )
            b.AddCategory( "2" )
            r.AddCategory("3")
            l.AddCategory("4")
            m.AddCategory("5")
           
            ramp.LoadMesh( "face2h.x" )
            ramp.Scale( 20,5,20 )
            ramp.MoveTo( 30, 2, 0 )
            ramp.TiltUp( 3 )
            ramp.EnableCollisions( "1" )
            ramp.Static = True
            ramp.AddCategory( "obstacle" )
           
            sky.LoadMesh( "skybox10.x" )
           
            f.EnableCollisions( "obstacle" )
           
        End Method
       
        Method Drive()
           
            front = ship.translatePoint(0, -10, 30 )
            back = ship.translatePoint(0, -10, -15 )
            right = ship.translatePoint(20, -10, 0 )
            left = ship.translatePoint(-20, -10, 0 )
            mid = ship.TranslatePoint(0, -11, 0 )
           
            f.Location = front
            b.Location = back
            r.Location = right
            l.Location = left
            m.Location = mid
           
            If iskeydown("up") Then
                ship.Forward( speed )
            End If
           
            If iskeydown("down") Then
                ship.Back( speed )
            End If
           
            If iskeydown("Right") Then
               
                ship.TurnRight( speed / 10 )
            End If
           
            If iskeydown("left") Then
               
                ship.TurnLeft( speed / 10 )
            End If
           
            If iskeydown(space) Then
               
            End If
           
            If iskeydown(shift) Then
                speed = speed + .2
            End If
           
        End Method
       
        Method AdjustShip()
            If f.HasCollision( ramp ) Then
                ship.TiltUp( 100 )
                ship.Back( speed )
            End If
        End Method
       
    End Program

     

     

  •  04-05-2007, 4:59 PM 3500 in reply to 3495

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    I downloaded this and am working on a solution(not that I'm an expert, but I do have some time).

    One thing that I noticed right off the bat is your method Adjustship().

    you have

    if f.HasCollision(ramp) then

        ship.tiltUp(100)

        ship.Back(speed)

    end if

    the problem is that once you get to the ramp you will have a collision every cycle of the main game loop so the ship will tilt up 100 every loop.

    ******** suggestion  ****

    create a boolean

    define collide as boolean = false

    if ship.HasCollision(ramp) then

        collide = true

    end if

    if collide = true

        ship.tiltUp(100)

    end if

    this will have the ship tilt up once, im not sure if you want the ship to tilt at the same angle as the ramp.

     

  •  04-05-2007, 11:07 PM 3502 in reply to 3500

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    Have you downloaded DriveMyShip yet?  It might be a handy example - in it, the 3D ships "bounce" back up when they hit the "ground."
  •  04-06-2007, 5:56 PM 3505 in reply to 3502

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    Yes, and I've made another 3D program and the collisions worked fine. I think I used a while loop to move the ship toward an object as long as the ship is not touching it. This created a sort of gravity. But somehow I cannot duplicate the collision handling.
  •  04-07-2007, 7:26 PM 3534 in reply to 3505

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    strange, i replaced the f.hasCollisions( ramp ) with ship.hasCollisions( ramp )( and made the proper changes) - the ship works exactly how it is supposed to? I will try to look further into it.
  •  02-18-2008, 10:31 AM 6118 in reply to 3384

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    what's face 2H?

    (\ _/)
    (- . -) This is bunneh. Copy and paste him to
    (")-(") your signature, so that he may gain popularity and eventually rule the world
  •  02-18-2008, 10:31 AM 6119 in reply to 3384

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    sorry: duplicate post

     



    (\ _/)
    (- . -) This is bunneh. Copy and paste him to
    (")-(") your signature, so that he may gain popularity and eventually rule the world
  •  02-18-2008, 1:52 PM 6120 in reply to 6118

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    hylaminer7729:
    what's face 2H?

     It's a basic 3D plane(flat surface). I have no idea why it's called Face2H.
     

  •  02-19-2008, 12:37 PM 6139 in reply to 6120

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    well, you should use ground.x, the one with the old BZphrog.

    (\ _/)
    (- . -) This is bunneh. Copy and paste him to
    (")-(") your signature, so that he may gain popularity and eventually rule the world
  •  02-19-2008, 1:02 PM 6140 in reply to 3384

    Re: Functionality/Feature Request - Postition(s) Relative to a 3D Object

    I have come up with a solution for you momentum problem.  If you have not already addressed it.

    Pseudocode -

    maxSpeed = 10.00;  minSpeed = 0.00;

         while acceleration key is down and speed < max speed, speed *= 1.1

         if speed = max speed, speed = max speed

        if acceleration key is not down and speed > min speed, speed *= .95

        if speed = min speed, speed = min speed

    end while

    basically - your speed starts out at zero, you press on the accleration and build up speed by 10 percent until you reach max speed.  Once you let go of the acceleration you speed will slowly decline by 5 percent.  All the values in this pseudocode may be changed, they are just examples.  I'm not sure if phrogram uses integer values or decimal values for it's .forward method( which is what I assume your using for movement) if it does not uses decimal values it may present a problem.  I will be interested to see if this code is helpful, I am going to try and implement it into my own game as well. 

Page 1 of 2 (21 items)   1 2 Next >
View as RSS news feed in XML