Moving a space ship in 3 dimensions, having a camera follow.
Posted 03 November 2008 - 01:23 AM
I've constructed a player node with the following objects:
Base node (invisible 'root' of my player object)
Camera node (attached to the root)
Model node (attached to the root)
Attractor node (attached to the root)
I move the attractor node up to 40 units in any direction around the center of the root node. Each frame, I set the center of the root node to the absolute position of the attractor node.
I use the attractor node as an expression of the forces acting on my player node. If its center matches the center of the root node, the ship doesn't move. Each frame, I move the attractor node slowly back toward the center, to emulate deceleration. Overall, it works pretty well :)
I move the attractor node forward and back, left and right by using WASD, and up/down by moving the mouse to the top 15% or bottom 15% of the screen.
My problem is that I am dependent on a particular orientation; If I change my orientation, forward/back and left/right lose their context, so WASD controls don't move the ship correctly in relation to the camera.
How can I make a movement system that moves through 3 dimensions according to the orientation of the camera?
Is the attractor node idea a bad way to go about it?
Posted 03 November 2008 - 02:10 AM
In any case, to be able to move in camera-relative directions, you'll have to use some trig and/or matrix math to compute the forward/right/up vectors based on the camera angle. If you have access to (or are already computing) the camera matrix, you can extract the vectors straightforwardly from it. I can't tell you how in detail without knowing how your coordinate system is oriented. You didn't say if you're using an engine or something you built on your own, but if it's an engine it may well have functions built in to get these vectors already.
Btw, I find a useful extension to WSAD is to use E and C for up and down.
Posted 03 November 2008 - 02:35 AM
For reference, the language I'm using is AutoIt script, and the engine is an Irrlicht plugin done by A.Percy of the AutoIt community. If you'd like to see what I have, http://www.autoitscr...showtopic=83709 has my code, and links to the project files. You'll also need AutoIt installed, which is a good idea in any case. ;)
Disclaimer: I'm not very familiar with 3D math or programming. I've gotten to the point where I've got the node moving around correctly if I don't mess with the camera. It's been mostly by trial and error, and a very cursory understanding of what I'm doing.
I can get and set rotation of any node along any axis, as well as get/set position of any node along any axis.
I can calculate rotation along any axis relative to the world, and I can get the "absolute" coordinates for a node as well.
The only vector object I have access to is the "Up Vector" for the camera. To be honest, I'm not sure what it is...
Is there a vector tutorial or general explanation you could point me at that covers issues like this? Thanks for the input!
Also, to clarify what I wanted from my "attractor node" idea:
My thought was to manually rotate the ship node along different axes to represent pitch, yaw, and roll. I wanted to calculate those values based on the relative position of the attractor Node, and set the camera look target toward the center of the ship node, and the position of the camera 100 units behind the ship node along the relative X axis.
Actual motion through the world occurs by setting the position of the root node which the attractor, ship, and camera node are attached to.
I was trying to come up with a way to skip learning about vectors, but since I have to learn anyway, I'd like to follow through and see how it works, anyway.
Posted 03 November 2008 - 02:53 AM
Here is a basic one about the physics of motion:
Posted 05 November 2008 - 10:40 AM
I did, however, need to understand the math, and I thank you again for pointing me at those tutorials.
I'm working out a simple vehicle system based on what I've learned, and it's giving the ships both a very realistic feel and look to the movement.
There is one quick piece of vector math I'm confused about, though. I need to compensate for my relative pitch. My angle is causing my pitch to reverse around my Up Vector... at 180 degrees, it works correctly, moving up and down, but at 360 degrees, it works in the opposite manner. I believe what I need is a sin or cos function operating on my degree of rotation, then applied to what I want my pitch to be, but... it is confusticating me, lol.
It's probably too late, and I'll see everything clearly tomorrow, but thanks anways! :)
Posted 05 November 2008 - 12:11 PM
I'll post some code sometime soon. :)
Posted 16 November 2008 - 07:40 PM
It implements 6 cameras and allows the user to switch between them at run-time. 1 of the cameras is a rubber band type system where it falls a little behind when the object speeds away and then settles into position once the object stops. The camera types it supports are Fixed, Tracking, First Person and ThirdPerson, Top Down Fixed and Top Down Tracking cameras.
The post about it can be found here
and the zip files that contains both C-Sharp and Object Pascal project can be downloaded here - http://chrome.pascal...as_Tutorial.zip
It is probably not the best implementation of such a thing, but it helped me understand cameras.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users