Help implementing shooting with straight animator

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
jhend60
Posts: 44
Joined: Mon Oct 27, 2008 10:11 am
Location: behind you
Contact:

Help implementing shooting with straight animator

Post 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.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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!
Image Image Image
jhend60
Posts: 44
Joined: Mon Oct 27, 2008 10:11 am
Location: behind you
Contact:

wha??

Post 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.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post 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 *.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
jhend60
Posts: 44
Joined: Mon Oct 27, 2008 10:11 am
Location: behind you
Contact:

OK got that

Post 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.
Post Reply