Jump to content

Bullet Raycasting


Shard
 Share

Recommended Posts

I had a few questions about doing bullet raycasting.

 

I have a gun, whose position and range I know. How do I do a raycast in a straight line from the gun? What I'm really meaning to ask is, if the player is turned sideway, what value should I increment so that the raycast is performed in a straight line from the players perspective?

 

 

Also, the Pick will return a Pick Object which will have a TEntity object in it. I recall a long time ago that it was possible to create a pointer to my coded classes (for enemies and whatnot) using , I think, Object userdata. Does anyone know how this works?

 

 

Basically I want to be able to trace if what was hit with the raycast, and if its a AI type, reduce its health. If its a wall, etc, create a bullet hole texture.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Also, the Pick will return a Pick Object which will have a TEntity object in it. I recall a long time ago that it was possible to create a pointer to my coded classes (for enemies and whatnot) using , I think, Object userdata. Does anyone know how this works?

That would require something like:

 

class MyCube
{
public:
   MyCube()
   {
       m_entity = CreateCube();
       SetEntityUserData(m_entity, static_cast<BP>(this));
   }
private:
   TEntity m_entity;
};

 

and then, once you know the picked entity:

 

MyCube& pickedCubeInstance = *(reinterpret_cast<MyCube*>(GetEntityUserData(pick.entity)));

untested, but this is the concept

 

I agree, this should rather be posted in the programming section.

 

As for the first question, if your game is a FPS, just use CameraPick from the middle of the screen.

If not, use a LinePick starting at the weapon model origin and ending at the point (0,0,<weaponrange>) relative to the weapon, converted to global coordinates using

TFormVector.

Link to comment
Share on other sites

That would require something like:

 

class MyCube
{
public:
   MyCube()
   {
       m_entity = CreateCube();
       SetEntityUserData(m_entity, static_cast<BP>(this));
   }
private:
   TEntity m_entity;
};

 

and then, once you know the picked entity:

 

MyCube& pickedCubeInstance = *(reinterpret_cast<MyCube*>(GetEntityUserData(pick.entity)));

untested, but this is the concept

 

I agree, this should rather be posted in the programming section.

 

As for the first question, if your game is a FPS, just use CameraPick from the middle of the screen.

If not, use a LinePick starting at the weapon model origin and ending at the point (0,0,<weaponrange>) relative to the weapon, converted to global coordinates using

TFormVector.

 

 

Thanks for that, TFormVector is what I was looking for. Just a quick question, how do I determine the position of the center of the screen?

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

GraphicsWidth()/2, GraphicsHeight()/2

 

I meant the 3D position of the center of the screen.

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...