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

Author Topic: [Resolved] FPS Camera Help  (Read 2583 times)

Names_Py

  • World Owners
  • ****
  • Posts: 6
    • View Profile
[Resolved] FPS Camera Help
« on: May 02, 12, 07:24:10 PM »

Hello I am new to Hero Engine, I followed to FPS Camera Tutorial on the wiki which at the end gave the code

Code: [Select]
function PushAndActivateFPS_CameraLayer()
  PushCmdLayer("FPS_Camera")
  ActivateCmdLayer("FPS_Camera", true)
.
 
function DeactivateFPS_CameraLayer()
  ActivateCmdLayer("FPS_Camera",false)
.
 
function SetupFPS_Camera()
  camera as NodeRef = AddCamera("FPS_Camera")
 
  character as NodeRef = GetPlayerCharacterNode()
  character_position as Vector3
  GetNodePosition( character, character_position )
  SetCameraPosition( "FPS_Camera", character_position )
  character["Render"] = false
 
  SetCameraFollow( "FPS_Camera",character )
  SetCameraOffset( "FPS_Camera", 0.0 )
  FreeLook( "FPS_Camera", true )
  ActivateCamera( "FPS_Camera")
.
 
function onmouseleaveviewport()
  println("Left viewport in fps_camera")
.
 
function OnMouseClick(lmb as Boolean, rmb as Boolean, mmb as Boolean, mb4 as Boolean, mb5 as Boolean) as Boolean
  println("Click")
  return false
.
 
function onMouseMove(mx as Integer, my as Integer, dx copies Integer, dy copies Integer) as Boolean
  println("Moving the mouse")
  if (GetTweakableBoolean("GameInvertMouseX")) or $INPUT._InputGameInvertMouseX
    dx = dx * -1
  .
  if (not GetTweakableBoolean("GameInvertMouseY")) and ( not $INPUT._InputGameInvertMouseY )
    dy = dy * -1
  .
 
  fx as Float = dx
  fy as Float = dy * -1
 
  if $INPUT._InputGameMouseSensitivity > 0
    fx = fx * $INPUT._InputGameMouseSensitivity
    fy = fy * $INPUT._InputGameMouseSensitivity
  .
  camera as NodeRef = GetActiveCamera()
  RotateNode(camera,fy,fx,0)
 
  return true
.
 
 
 
function StartFPS_Camera()
  PushAndActivateFPS_CameraLayer()
  SetupFPS_Camera()
.

I understand what the code is doing and all but I try to call the StartFPS_Camera() function through the console to test the code and I get nothing. I used the call command as stated in the wiki by typing:
CALL FPS_Camera_Callback StartFPS_Camera
and nothing happens. The console doesn't kick out any errors but the camera doesn't change at all either. Is there something I missed?
« Last Edit: Sep 26, 12, 09:40:53 AM by HE-Cooper »
Logged

Names_Py

  • World Owners
  • ****
  • Posts: 6
    • View Profile
Re: FPS Camera Help
« Reply #1 on: May 02, 12, 07:39:26 PM »

Figured it out. My GameKeyBindings.ini file didn't save/upload correctly.

One thing I noticed is that whenever you move the mouse/camera it sends a message to the command interface. Is there a way to suppress that? Makes it hard to see anything else for debugging purpose with it spamming the crap out it whenever the mouse is moved.

Also noticed a real nasty flaw using the stock fps camera as is. Scrolling still changes the camera distance.
Also inverting Y doesn't actually affect the Y axis camera movement, any thoughts? I have work soon but will start fresh tomorrow and see if I can't get it to work as I want and will post the progress here.
« Last Edit: May 02, 12, 07:48:46 PM by Names_Py »
Logged

Chromehound

  • General Accounts
  • *
  • Posts: 151
    • View Profile
Re: FPS Camera Help
« Reply #2 on: May 02, 12, 11:32:31 PM »

the println function is what sends text to the chat
Logged

Names_Py

  • World Owners
  • ****
  • Posts: 6
    • View Profile
Re: FPS Camera Help
« Reply #3 on: May 03, 12, 06:44:35 AM »

I'll have to look at that and see if I can't add or remove something to suppress that message then thank you.
Logged

XCalPro

  • General Accounts
  • *
  • Posts: 105
  • 3D Artist & HSL Coder
    • View Profile
    • Excalibur Productions
Re: FPS Camera Help
« Reply #4 on: May 03, 12, 08:35:42 AM »

Just comment out the line: println("Moving the mouse") in function onMouseMove()
Logged
Tony Oliveira aka XCalPro
HeroEngine Projects: Traveller 6 Online - www.traveller6.com/forum/
Portfolio: www.xcalpro.com/art

Names_Py

  • World Owners
  • ****
  • Posts: 6
    • View Profile
Re: FPS Camera Help
« Reply #5 on: May 03, 12, 05:49:24 PM »

Yeh was pretty tired when I made my last comment thanks for the help. For some reason though I can make the invert Y work. Regardless if InvertY is checked on or off MouseUp moves the camera down and MouseDown moves it up, any suggestions on what I am doing wrong?
Logged

HE-Cooper

  • *****
  • Posts: 2221
    • View Profile
Re: FPS Camera Help
« Reply #6 on: May 03, 12, 06:50:02 PM »

First you'll want to make distinction between editor settings, which are just for the editor, and game settings. You could look at the default camera to see where the invert Y is being called from the render panel, but you'd be better served implementing invert Y for your game.

Which would involve a variable and setting the y movement to be - or positive in relation to the mouse movement based on that variable. And you could have your players set that variable via a check box or a button in a menu you create.
Logged

Names_Py

  • World Owners
  • ****
  • Posts: 6
    • View Profile
Re: FPS Camera Help
« Reply #7 on: May 04, 12, 06:55:40 AM »

I thought it was already implemented in the engine. I know the invert X check box affects this function correctly but the invert Y does not. I assumed if one was coded to work using the tweakable boolean function the other would as well. I'll look into making my own and adding it then if it isn't already. Thanks.
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: FPS Camera Help
« Reply #8 on: Jun 30, 12, 11:42:54 PM »

Doing the same tutorial and most of it seems to be working but the onMouseMove isn't firing or at least the handler in this script isn't being hit.  Neither is the OnMouseClick though that isn't of much importance to me at the moment.

onmouseleaveviewport is firing, but not those two events.  The camera is being created and moving to the proper position from the setup function.

Edit:

Changing the gamebindings.ini section to this seems to have fixed it though it doesn't change the direction of the the character, but that doesn't seem to be handled by the tutorial code:


Code: [Select]
[FPS_Camera] = FPS_Camera_Callback
  DefaultBinding = ANY
« Last Edit: Jun 30, 12, 11:57:45 PM by DragonFist »
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: FPS Camera Help
« Reply #9 on: Jul 01, 12, 01:47:39 AM »

Going to bed now, but getting character to follow camera rotation has me a bit stumped.
Logged

Scelus

  • World Owners
  • ****
  • Posts: 9
    • View Profile
Re: FPS Camera Help
« Reply #10 on: Jul 17, 12, 02:29:49 PM »

I have a problem in this deployment and would like to take advantage of the Topic.

Once implemented FPS_Camera movement is okay. By moving the mouse the camera marketing year the movement of the mouse, however the front of the character keeps pointing to the same place. Does anyone have a light on how this implentar FPS so that the floor of the character to follow the direction of the mouse?

Thanks
Logged

DragonFist

  • General Accounts
  • *
  • Posts: 140
    • View Profile
Re: FPS Camera Help
« Reply #11 on: Jul 17, 12, 04:35:13 PM »

I believe this had to do with setting camera follow offset.

Not able to look at the code now but iirc need to make sure you set camera follow to true and give it an offset (even if it is 0.0).
Logged

Critta

  • World Owners
  • ****
  • Posts: 2
    • View Profile
Re: FPS Camera Help
« Reply #12 on: Sep 17, 12, 07:19:38 PM »

Changing the gamebindings.ini section to this seems to have fixed it though it doesn't change the direction of the the character, but that doesn't seem to be handled by the tutorial code:


Code: [Select]
[FPS_Camera] = FPS_Camera_Callback
  DefaultBinding = ANY

Have also followed the tutorial and hit the same problem, have tried the fix stated by DragonFist here, but for some reason I can't get the camera to catch the onMouseMove or onMouseClick events to save my life.

I'm wondering if I'm being dense and failing to use the repository browser properly, or missing a command to reload the commands from gamebindings.ini, have tried changing areas, logging in and out but no luck.

Anyone got any idea what I'm doing wrong?
Logged

Critta

  • World Owners
  • ****
  • Posts: 2
    • View Profile
Re: FPS Camera Help
« Reply #13 on: Sep 18, 12, 05:48:46 PM »

Seem to have fixed it by moving things into the Input_Camera script. Not sure why the new cmd layer from the tutorial fails to catch the mouse events, I tried all sorts whilst trying to work it out, including disabling all of the other command layers to check none of them were handling the input before it got to the new one.

Now to figure out tying the player rotation to the camera :)
Logged