Jump to content
  • Advertisement
Sign in to follow this  
Berryblue031

3rd person camera math help

This topic is 3664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am trying to get a third person camera working, I have been refering to tonnes of articles and threads on the topics but I just can't get the smooth turning math working, so I was hoping if I posted my specific situation somebody could give me a hand. What I am aiming for: Positioning: Behind the character but offset by an arbitrary (x,y,z) and an arbitrary pitch (p) kind of like how it is in Gears of War where the player is offset to the side of the screen. Behavior: Forward vectors of camera and character need to match so the camera is looking in the same direction as the player. I would like some lag in the movement so when you turn for example the camera rotates smoothly preferably a spring system, currently this is my biggest problem if I just set the camera forward equal to the player forward when you turn it is way to fast and disorienting but I can't get it to interpolate properly. The same problem with positioning if the player makes essentially a 90degree turn the camera shouldn't just cut across the shortest path to position itself i should do gradual turn. I have been trying to solve this by using a VELOCITY based approach but something is missing. I am working in a framework so the function I have access to is structured like this Vector3 Camera.Position Matrix3x3 Camera.Rotation ( Camera.Rotation.Axis(0) is the forward ) Vector3 Player.Position Matrix3x3 Player.Rotation void Update(float deltaTime) { //Get desired camera values by applying offsets to current player values //Figure out new camera values by interpolating from current to desired Camera.Position = newPosition Camera.Rotation = newRotation } Thank you

Share this post


Link to post
Share on other sites
Advertisement
Although the camera in that example does move smoothly, it isn't quite what I am looking for

The camera in the example is always trying to look at the player from directly behind; I am trying to make a camera that is always looking parallel to the player's forward vector from a position behind and to the side, i.e. directly behind the players shoulder.... I am trying to mod the example to give that affect but I am not having any luck

Share this post


Link to post
Share on other sites
If you know the players position as a starting point, and you know the players various directions (forward, right, up) offset from the players position to the point you want to be looking at. Some quick vector math for example
position + (right * horizontalOffset) + (up * verticalOffset) would give you a point to the right and above the players position to look at, try making that your target point to look at, then make sure the camera swings quickly behind horizontally about the up axis, then make sure the vertical or pitch angle is correct so its looking parallel with the characters direction and not pitching up or down about the side vector.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!