Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Capping the mouse and jumping.  (Read 627 times)
0 Members and 1 Guest are viewing this topic.
Offline synok

Senior Newbie


Medals: 1



« Posted 2013-10-16 12:38:32 »

Hello everyone,

First of all, I don't know if my title makes sense. But I have followed http://www.lloydgoodall.com/tutorials/first-person-camera-control-with-lwjgl/ in order to get a sort of FPS camera going.

It works aaalmost perfectly, but if you look for example too much up, I end up looking upside down, and I can spin all the way around. Does anyone know how to "cap" the axis at a specific point to prevent this?

Yet another question, I am using this code to move also. But is there anyone who knows how to jump? I guess there is a lot of velocity and stuff involved, but can anyone give a good example?

Thanks,

EDIT: Kind of fixed the capping now by adding if statements in the lookThrough method inside the Camera class. Just checked if the axis hit a specific angle and increasing / decreasing the pitch by respective angle. Quick and dirty fix and the camera is jittering, but it works.
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-10-16 21:40:26 »

For the vector part, simple jumping is easy. Have a 2D vector and set the y component to something like -12. Then create another variable called gravity and set it to maybe 0.5. Every frame add the vector to the gravity variable.

Offline synok

Senior Newbie


Medals: 1



« Reply #2 - Posted 2013-10-21 13:38:30 »

For the jumping part I add this code in my class that handles input:

1  
2  
3  
4  
5  
6  
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
            jumping = true;
            if(jumping){
               
            }
        }


Now for the interesting. What should be inside

1  
if(jumping)


I have a camera class with a 3D vector for position. How can I use the Y-axis for jumping in it? The camera position is defined by:
1  
camera.position.y


Please help.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Dxu1994
« Reply #3 - Posted 2013-10-21 13:41:13 »

You need to limit the pitch, or whatever you want to call it.

for example:
1  
pitch = Math.min(Math.max(yaw+mouseDiff, MIN_PITCH), MAX_PITCH);


As for jumping, just subtract a number from your z and bound this number between 0 and a number, add a number to this and bound it every step to create gravity.

1  
2  
3  
void doJump() {
 if (z == 0) z -= 10;
}


and in your step:

1  
z = Math.min(0, z + gravity);

Offline synok

Senior Newbie


Medals: 1



« Reply #4 - Posted 2013-10-21 13:54:01 »

You need to limit the pitch, or whatever you want to call it.

for example:
1  
pitch = Math.min(Math.max(yaw+mouseDiff, MIN_PITCH), MAX_PITCH);


As for jumping, just subtract a number from your z and bound this number between 0 and a number, add a number to this and bound it every step to create gravity.

1  
2  
3  
void doJump() {
 if (z == 0) z -= 10;
}


and in your step:

1  
z = Math.min(0, z + gravity);


Now where does the pitch come in? Can you help me in forms of the code I provided? I suck at this.

EDIT: Oh, thought the pitch was jump related. That is what got me confused.

EDIT 2: Got it working with your code! Thank you Smiley He is jumping very fast though. Can I fix this?
Offline Dxu1994
« Reply #5 - Posted 2013-10-21 14:08:02 »

Yep, just tweak the numbers.

The first piece of code I posted was to help you fix the mouse limiting problem

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (74 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!