Hello again.
I need to shoot a proyectile from the player´s weapon towards the mouse. The game´s view is top-down and the player is always on the center of the screen and is always "looking" towards the mouse also.
I need that the player can shoot towards the aim (mouse).
I first thought in select a triangle from the ground as a reference, but they are bigger that the mouse and could affect accuracy.
I need a clue in how to get the mouse position in 3D, or other idea in how to face the problem from another angle, that im probably missing.
3D mouse position [solved]
3D mouse position [solved]
Last edited by Malebolge on Sun Sep 28, 2008 2:54 pm, edited 1 time in total.
if you look at tutorial 07.Collision you'll se it not only gets the triangle of the collision, but also the collision point, that would be more accurate then...
but if your player is always in the center of the screen you also can use the screen coordinate instead, I think...
but if your player is always in the center of the screen you also can use the screen coordinate instead, I think...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
The general idea is to cast a ray through the mouse co-ordinates, and then collide it against something.
The "something" that you collide it with depends on your problem domain. It can be a plane, or a triangle selector. It sounds like you'll want to collide with the terrain, using a triangle selector, as shown here.
That will get you the position on the terrain. However, since it's unlikely that you actually want to shoot at the ground, I'd expect that you'll want to (e.g.) shift the aim point straight up, by (again, e.g.) the same height as the gun.
The "something" that you collide it with depends on your problem domain. It can be a plane, or a triangle selector. It sounds like you'll want to collide with the terrain, using a triangle selector, as shown here.
Code: Select all
if(eventReceiver.ButtonClicked)
{
const position2di clickPosition = device->getCursorControl()->getPosition();
const line3df ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(clickPosition, smgr->getActiveCamera());
vector3df desiredPosition;
triangle3df outTriangle;
if(smgr->getSceneCollisionManager()->getCollisionPoint(ray, terrainSelector, desiredPosition, outTriangle))
{
formation->DesiredPosition = desiredPosition;
}
}
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
yes, i saw that but the example use 3d coords, the camera position and the camera target position.Acki wrote:if you look at tutorial 07.Collision you'll se it not only gets the triangle of the collision, but also the collision point, that would be more accurate then...
but if your player is always in the center of the screen you also can use the screen coordinate instead, I think...
Code: Select all
core::line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;
core::vector3df intersection;
core::triangle3df tri;
Thanks again, i´ll give it a try.rogerborg wrote:The general idea is to cast a ray through the mouse co-ordinates, and then collide it against something.
The "something" that you collide it with depends on your problem domain. It can be a plane, or a triangle selector. It sounds like you'll want to collide with the terrain, using a triangle selector, as shown here.
That will get you the position on the terrain. However, since it's unlikely that you actually want to shoot at the ground, I'd expect that you'll want to (e.g.) shift the aim point straight up, by (again, e.g.) the same height as the gun.Code: Select all
if(eventReceiver.ButtonClicked) { const position2di clickPosition = device->getCursorControl()->getPosition(); const line3df ray = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(clickPosition, smgr->getActiveCamera()); vector3df desiredPosition; triangle3df outTriangle; if(smgr->getSceneCollisionManager()->getCollisionPoint(ray, terrainSelector, desiredPosition, outTriangle)) { formation->DesiredPosition = desiredPosition; } }
but you need the 3d coords, don't you ???Malebolge wrote:yes, i saw that but the example use 3d coords, the camera position and the camera target position.
also you need a camera, or from where you should get any coords otherwise ???
that the example only uses the cams target is just for easyness, it so just uses the center of the screen this way, but you can use any screen coordinate you want (like rogerborg showed)...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Yes, i just post that at the same time as rogerborg jeje. I see the answer clear now. Thanks to both.Acki wrote:but you need the 3d coords, don't you ???Malebolge wrote:yes, i saw that but the example use 3d coords, the camera position and the camera target position.
also you need a camera, or from where you should get any coords otherwise ???
that the example only uses the cams target is just for easyness, it so just uses the center of the screen this way, but you can use any screen coordinate you want (like rogerborg showed)...