Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Determine Front vector???  (Read 809 times)
analysis_junky
Customers
Community Member
*****
Posts: 144


WWW
« on: May 11, 2008, 10:38:56 AM »


I feel stupid for not being able to figure this simple problem out on my own, but here goes...


I am trying to get a physics movement system going with a 3rd person camera. I have everything working EXCEPT the correct movement values once the w,a,s,d buttons are pressed.

I have tried:
Physics.AddImpulse
Physics.SetForce
Physics.SetBodyLinearVelocity
Physics.SetBodyAngularVelocity


The primary issue is determining FRONT, BACK LEFT, and RIGHT.

My initial idea to determine this is to get the cam position and add/multiply the actor's position. I thought this would give me the FRONT vector position...

I am stumped. If anyone could give me a hand in this I would be greatly appreciated!

Thanks!

Logged

Project: Eternis Prime
analysis_junky
Customers
Community Member
*****
Posts: 144


WWW
« Reply #1 on: May 11, 2008, 02:56:03 PM »

anyone?
Logged

Project: Eternis Prime
jviper
Community Member
*
Posts: 1255

Discipline in training


« Reply #2 on: May 11, 2008, 06:52:33 PM »

if you have the tvmesh that you connected the physocs body, you can use the function GetBasisVectors. The function returns the FrontVector, UpVector, and SideVector vis Byref.

Your Foward would be FrontVector
Your Back would be -1*FronVector
Your Right would be SideVector
Your Left would be -1*SideVector
Logged

JAbstract.....Don't just imagine, make it happen!
analysis_junky
Customers
Community Member
*****
Posts: 144


WWW
« Reply #3 on: May 11, 2008, 07:38:01 PM »

thanks! I have never used that function...
I will try it  Cheesy
Logged

Project: Eternis Prime
analysis_junky
Customers
Community Member
*****
Posts: 144


WWW
« Reply #4 on: May 12, 2008, 07:01:33 AM »


GetBasisVectors worked for getting the values but I am not sure how to use them properly.

1.) When I turn the camera I want the target actor/mesh to turn also (facing away from the camera, or front) so that the target actor/mesh is always changing its front vector.

2.) From what I have seen, when using Physics I am not able to use the TV functions to move or rotate the actor/mesh: ex. MoveRelative, SetRotation

     a. Which Physics function is the best for making a 3rd person character controller?

     b. What is the best way to get the proper angle/force/position/etc values to pass to the Physics movement function to get correct 3rd person movements?


I have done tons of searches and haven't found a good solution for my problem. If anyone has tackled this issue please help  Smiley

Thanks in advance!

Logged

Project: Eternis Prime
analysis_junky
Customers
Community Member
*****
Posts: 144


WWW
« Reply #5 on: May 13, 2008, 10:56:35 AM »


Has anyone found a solution?
Logged

Project: Eternis Prime
HRuivo
Community Member
*
Posts: 16


« Reply #6 on: May 13, 2008, 12:18:06 PM »

I wish I had it. I'm looking too on a way to get the right vector for the addImpulse() or SetBodyLinearVelocity() functions.
Logged
sciophyte
Customers
Community Member
*****
Posts: 207


« Reply #7 on: May 13, 2008, 01:23:53 PM »

addimpules and linear velocity have a localspace parameter, so u can apply the vectors relative to the body orientation.
Logged
analysis_junky
Customers
Community Member
*****
Posts: 144


WWW
« Reply #8 on: May 13, 2008, 02:19:04 PM »


Yeah, but how do I get/use the local space vectors to apply accurate movement?

I have tried GetBasisVectors but because my model is moved with Physics the values don't seem to be correct...

What I have been trying to do is:

Calculate a ray from the camera position to the model's position, then call that the front vector and maybe add 10 units.
What would be the proper way to do this? I'm sure if I had the correct values I could figure the movement stuff out on my own.
Logged

Project: Eternis Prime
sciophyte
Customers
Community Member
*****
Posts: 207


« Reply #9 on: May 13, 2008, 03:02:46 PM »

with the localspace flag +z is always forward -z is always backward, +x is right etc...

so using linearvelocity,

tvphysics.setbodylinearvelocity(bodyindex, vector(0,0,1), true)

will set the linear velocity at 1 on the z axis which is always forward with localspace = true
Logged
HRuivo
Community Member
*
Posts: 16


« Reply #10 on: May 13, 2008, 05:18:58 PM »

wow, thanks alot sciophyte.
Now I know what localspace is for.
I just need to use SetbodyAngularVelocity() or SetbodyRotation() to rotate the actor to the right direction and use SetbodyLinearvelocity to move it.
thank you one more time.

Logged
analysis_junky
Customers
Community Member
*****
Posts: 144


WWW
« Reply #11 on: May 13, 2008, 05:56:17 PM »


I finally got it to work, thanks to all that helped.

My situation seemed different and the normal solutions didn't seem to fix the issue.

Here is what I had to do:

1.  Set a lookAt variable
lookAt = Camera.GetFrontPosition(.005f);

2.  Set the lookAt of the mesh
Mesh.LookAtPoint(lookAt);

3.  Use the lookAt vector to convert to "local space"
vLocal = MathLibrary.ConvertToLocalSpace(lookAt, Mesh.GetPosition());
vLocal.y = 0;
               
Physics.SetBodyLinearVelocity(iPhysicsBody, vLocal, false);

4.  Use the Inverse function to go the opposite direction.

Note: The ConvertToLocalSpace function may be incorrect because the SetBodyLinearVelocity function only works correctly with the localSpace flag set to false.

Code:
public static TV_3DVECTOR ConvertToLocalSpace(TV_3DVECTOR worldSpace, TV_3DVECTOR center)
        {
            TV_3DVECTOR retVector = new TV_3DVECTOR();
            retVector.x = center.x - worldSpace.x;
            retVector.y = center.y - worldSpace.y;
            retVector.z = center.z - worldSpace.z;

            return retVector;
        }
        public static TV_3DVECTOR Inverse(TV_3DVECTOR v)
        {
            TV_3DVECTOR retVector = new TV_3DVECTOR();
            retVector.x = v.x - (v.x * 2);
            retVector.y = v.y - (v.y * 2);
            retVector.z = v.z - (v.z * 2);

            return retVector;
        }

Thanks again!
Logged

Project: Eternis Prime
jviper
Community Member
*
Posts: 1255

Discipline in training


« Reply #12 on: June 09, 2008, 01:13:23 PM »

Sorry for the delay in reponse to the question and the solution may have already been found. If you have the direction you want but you want to move in that direction based on the camera, all you have to do is take that direction and multiply it my the rotation matrix of your camera:

ActualDirection = TVMath.VecTransformCoord(Direction,TVCamera.GetRotationMatrix)

I think ActualDirection = TVCamera.GetRotationMatrix * Direction will work also.
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