Page 1 of 1

Help implementing shooting with straight animator

Posted: Tue Nov 04, 2008 8:58 am
by jhend60
Hi all again
How will I use this code (posted by JP)
core::vector3df direction = (endPos - startPos).normalize; // unit vector in the direction it should travel
fireball->setPosition(fireball->getPosition() + direction * FACTOR); // add on the unit direction to the current position and multiply it by FACTOR
but instead use the current direction of the camera?
I am using a completely flat surface now (collisions with mesh got out of hand) and just want to create a 3d projectile ( a box, in this instance) to shoot out from the camera and fly in whatever direction the camera is pointing at. I don't want it to stop for some reason (like the code I have now) and just want it to KEEP going (until draw distance hit). I also need to be able to implement it in my current code, and use it upon a keypress (already implemented keypress). If you want to look at my current code. just ask. I will use collision detection with the cube as well (should be do-able).

If I (you :roll: ) can get this working, next I will attempt to use a crosshair for aiming.

Thanks.

Posted: Tue Nov 04, 2008 9:33 am
by JP
It's explained in the tutorials.... surely when you start using a new bit of software you'd go and check out all the tutorials to learn about the key features of that software... no?

If you'd looked at the Demo tutorial then you'd know how to do this, so i suggest you go and look it over now!

wha??

Posted: Tue Nov 04, 2008 12:36 pm
by jhend60
I have already tried examining the Demo, but as you might know there isn't very good documentation for it, like all of the other tutorials! So it gives me code, with no way of understanding it! I need to be able to understand the code I write, or i will not even understand what is going on.

Posted: Tue Nov 04, 2008 1:02 pm
by rogerborg

Code: Select all

core::vector3df direction = (endPos - startPos).normalize; // unit vector in the direction it should travel 
We're trying to help you learn to learn. Alternatively, you can skip to the end for the answer. ;)

You need a direction vector. In the example given, that's created by subtracting a startPos (a vector3df) from an endPos (another vector3df).

To create a vector that represents the direction that the camera is looking, the same principle applies; find an end point, and subtract a start point. The start point is (hopefully obviously) the position of the camera.

What to use for an end point? How about the position that the camera is looking at? If you look in ICameraSceneNode.h, you'll find getTarget(), which returns a vector3df. Bingo.

So your code is:

Code: Select all

core::vector3df direction = (camera->getTarget() - camera->getAbsolutePosition()).normalize(); // unit vector in the direction the camera is looking
where camera is an ICameraSceneNode *.

OK got that

Posted: Tue Nov 04, 2008 1:25 pm
by jhend60
Okay I got that (along with other things-- figured out how to use irr mesh :lol: with collisions! YEAH! FINALLY. it just clicked lol. Anyway please read my new topic (REALLY NOOB QUESTION) probably so easy to fix. Thanks. That will be all I will need and then I will be on my way.