HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: [Resolved] Limit the y position of the camera (up and down)  (Read 1359 times)

Scelus

  • World Owners
  • ****
  • Posts: 9
    • View Profile

Hello

I'm working with the camera. The character in third person with a mouse, if I run the mouse to the right, the character will turn right, left if the character will turn left if I look up or down the character but still keeps camera will show up and down. That was exactly what I wanted.

But I would limit the position of the camera on the y axis or do not want to allow to look up the camera is positioned below the character or if you look down the camera is positioned at the head of the character.

I think the indicators to y I would like to limit are -0.084562086 and 0.314613104


I made an implementation, but did not like the result because the camera is giving short hops when it comes to certain limits. I would like the camera is static is simply the y position, but their movement is taken up if the direction was contrary to the limitation.

Currently I am leaving with the "hop" for answers, but would like to improve.

Look at the piece of code that I implemented (the basis of improvisation) to limit the angle.

Code: [Select]
camPosition as Vector3 = GetCameraPosition("GAME")
     
      if camPosition.y <= -0.084562086
        RotateNode(cam,1,fx,0)
      else if camPosition.y >= 0.314613104
         RotateNode(cam,-1,fx,0)
      else
        RotateNode(cam,fy,fx,0) 
      .

Otherwise I'm happy with this study!

Thanks to all
« Last Edit: Nov 02, 12, 08:55:12 PM by HE-Cooper »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.

First, I would recommend instead of having limits in terms of camera position, you have the limits be on camera rotation.

In your code, every time the camera goes past a limit, your code does a RotateNode in the opposite direction.  That is causing the "hopping".  Instead, if it is already at or past a limit when the function begins AND it is trying rotate more in that direction, it should not do nothing but return.  That will keep the camera still. 

If it gets past that check and applying the fy value would cause the camera to go to or past the limit, change fy so it would only leave the camera at the limit, then apply the rotation with whatever fy is at that point.
« Last Edit: Jul 18, 12, 07:13:10 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile

What Scott said.

Also, make sure you have this not only in your camera set-up and mouse move handlers, but also in the onframeupdate().  You'll find similar code for addressing limits on the mouse wheel already existing for the clean engine.  A lot can be done there.
Logged

Scelus

  • World Owners
  • ****
  • Posts: 9
    • View Profile

Hi.

I do not quite understand where to draw the limit of the camera. When you say "you have the limits be on camera rotation."
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.

You can do it experimentally:

With the camera able to rotate fully, put it at lower angle you want to be the limit.  Then get the rotation of the camera at that moment

*EDIT*
I realized you don't need to get the camera rotation in script.  The renderer panel of HeroBlade shows the current rotation of the camera at any given time.
*EDIT*

 and that will be one limit for rotation.  Do the same for your desired upper limit.

And the vertical angling of the camera is set by the x component of its rotation (which is why fy, the vertical movement of the mouse, is applied to the x parameter of RotateNode().
« Last Edit: Jul 19, 12, 02:51:26 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Scelus

  • World Owners
  • ****
  • Posts: 9
    • View Profile

Good day.

Partner, I ideintifiquei values ​​Position and Rotation of the camera I want, especially Rotation.

But still do not understand how I will limit this Rotation. I have since increased and decreased the rotation will have passed through the camera SetRotationNode

I'd have to check the current rotation of the camera? because it found only one GetCameraRotation GetCameraPosition.

I still can not identify the line of reasoning, maybe can be up to the translation ....

I appreciate your help, please proceed.
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.

It is true: although there is a "GetCameraPosition" function, there is no "GetCameraRotation" function.  However, you can use GetNodeRotation on cameras to get their rotation.

If you put this code after "fy" is ready to be used, this will work fine: (if you use GetActiveCamera() instead of AddCamera(), it will work for any active camera)

Code: [Select]
  //Limit angle to be from -40 degrees to 40 degrees:
  lowLimit as Float = -40
  highLimit as Float = 40

  var cam = GetActiveCamera() // AddCamera("GAME")
  var camRotation = GetNodeRotation(cam)
  if fy < 0
    //Trying to go lower:
    if (camRotation.x+fy) <= lowLimit
      fy = lowLimit - camRotation.x
    .
  else if fy > 0
    //Trying to go higher:
    if (camRotation.x+fy) >= highLimit
      fy = highLimit - camRotation.x
    .
  .
  RotateNode(cam, fy, fx, 0)
« Last Edit: Jul 23, 12, 03:18:38 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Scelus

  • World Owners
  • ****
  • Posts: 9
    • View Profile

Hi,

As I have said, I'm still learning, and much remains. There were reminded of the "GetNodeRotation" despite having read about it.

As soon as I can read this code with your calm, From what I've read is pretty simple. I understand it and apply the changes to my code then put the result here.

Thank you.
Logged