Need to get the box moving where it's facing

I’m sorry i’m making this post again… but i’m desperate by this point. I use Vector3f walkDirection = cam.getDirection();



Yeah, works… But, when you move the camera up or down the box gets slower or faster in that order. I tried to do some math but didn’t figure anything out. Already asked on gamedev.com too… Welp ):



Thank you for your time.

I’ll put down the code here for you but really, you won’t have any fun doing games at all if you don’t understand this code 100%, copy&paste will not make you a happy camper. Better have a look at this: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

[java]//clone cam direction, else we modify it

Vector3f walkDirection = cam.getDirection.clone();

//remove y component (up/down)

walkDirection.setY(0);

//normalize vector (make length=1)

walkDirection.normalizeLocal();

//multiply length with speed of unit

walkDirection.multLocal(speed);[/java]

1 Like
@normen said:
I'll put down the code here for you but really, you won't have any fun doing games at all if you don't understand this code 100%, copy&paste will not make you a happy camper. Better have a look at this: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies
[java]//*clone* cam direction, else we modify it
Vector3f walkDirection = cam.getDirection.clone();
//remove y component (up/down)
walkDirection.setY(0);
//normalize vector (make length=1)
walkDirection.normalizeLocal();
//multiply length with speed of unit
walkDirection.multLocal(speed);[/java]


Not suprisingly it works! Thank you, and thank you for the link too, I will study vectors some more. Well, you are right. I didn't have fun copy pasting, but I did make my own collision detection and everything else. But, when I find out more about vectors i'm probably gonna make my own code for making the box more where it's facing.

By the way, why do you want to use cam.getDirection.clone();, can't you just use cam.getDirection? Or, is it just for good practise?

sigh… i put a comment above it… you’d modify the cam direction vector else. thanks for proving that you indeed just copy-pasted the code. :facepalm:

@normen said:
sigh... i put a comment above it.. you'd modify the cam direction vector else. thanks for proving that you indeed just copy-pasted the code. :facepalm:


Well, ofcourse I copy pasted, what else am I suppose to do with it? But, I now know how to normalize vectors without having to do all the math myself.

Look at and understand the code, then write it into your application. I just wrote that off the top of my head and most anyone here in the forum could cause its not hard. Thats what I meant.

@normen said:
Look at and understand the code, then write it into your application. I just wrote that off the top of my head and most anyone here in the forum could cause its not hard. Thats what I meant.

@normen said:
Look at and understand the code, then write it into your application. I just wrote that off the top of my head and most anyone here in the forum could cause its not hard. Thats what I meant.


This is literally my third day with this engine, trying to get the block move where I need it to. And, i'm really sorry for not knowing how to do it... yeah, I tried to find the answer myself for plenty of time before asking here.

This is exemplified in one of the tutorials, I suggest doing those first, they make you do only stuff that is explained and when you’re done this problem here should be a no-brainer. We spent lots of time (surely more than three days) writing the documentation also for people who do not know much about the topics at hand. So I was just pointing out that if you just ditch the tutorials and do stuff “on your own” you will not get far without being able to normalize or rotate a vector which is explained in the tutorials.



To freely quote the muppets show: “If a german engineer tells you to hold your hat he’s not making casual conversation. Hold - your - hat! Hat! Hold!”. I promise you that if you actually read all the “math for dummies” you will find this easy too. And that if you also do all tutorials you will have no issues moving, rotation and even jumping around with your spatials.

@normen said:
This is exemplified in one of the tutorials, I suggest doing those first, they make you do only stuff that is explained and when you're done this problem here should be a no-brainer. We spent lots of time (surely more than three days) writing the documentation also for people who do not know much about the topics at hand. So I was just pointing out that if you just ditch the tutorials and do stuff "on your own" you will not get far without being able to normalize or rotate a vector which is explained in the tutorials.

To freely quote the muppets show: "If a german engineer tells you to hold your hat he's not making casual conversation. Hold - your - hat! Hat! Hold!". I promise you that if you actually read all the "math for dummies" you will find this easy too. And that if you also do all tutorials you will have no issues moving, rotation and even jumping around with your spatials.

That's what I was doing for the past time.

If thats really the case (like really, you can lie to me but you can hopefully not lie to yourself too well) and you did all tutorials and read the math for dummies more than once and still cannot make a box move at a direction then really, stop game development.

@normen said:
If thats really the case (like really, you can lie to me but you can hopefully not lie to yourself too well) and you did all tutorials and read the math for dummies more than once and still cannot make a box move at a direction then really, stop game development.


I'm glad you think that way.