Jump to content

shoot with physics


Rick
 Share

Recommended Posts

If I want to "shoot" something forward with physics and not have it drop at all or so little it's not noticeable, but not have it move all that fast, what functions/values should I be looking at? I never really messed around with physic projectiles before.

Link to comment
Share on other sites

Perhaps the following:

  • Do not set a mass for the object.

 

No, this makes a body totally immovable. You can't move it and no matter how small it is, if you place it on a train track -- worry about the train... It could be less than 1 mm wide, but if it's got no mass, nothing will move it...

 

Turn off gravity and apply the "adjusted" (negligible) gravity yourself every frame. It's what you'd have to do if you were using raw, unwrapped Newton.

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

@Aggor

 

I have a sphere csg object with a sphere rigid body where it has no mass to it. I place it right in front of the camera and call AddForce(0, 0, 100 * Time:GetSpeed()) one time to it and it just sits there in mid-air :)

Link to comment
Share on other sites

Hi Rick

 

This does it it's pretty much a cut and paste from my code so just let me know if you need any help as some bit's wont make sense. I also created a custom collision type too if you are wondering....

 

//Get the projectile direction

Mat4 matrix = character->GetTargetEntity()->GetMatrix();

 

projectileVelocity = character->GetTargetEntity()->GetMatrix()[2].xyz() * 900;

 

 

 

//Create the bulllet

 

Shape* shape = Shape::Box(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.1F, 0.1F);

GetTargetEntity()->SetShape(shape);

shape->Release();

 

 

GetTargetEntity()->SetPhysicsMode(Entity::RigidBodyPhysics);

 

GetTargetEntity()->SetMass(1);

 

GetTargetEntity()->SetCollisionType(kCollisionProjectile);

 

GetTargetEntity()->SetGravityMode(0);

 

GetTargetEntity()->AddForce(projectileVelocity);

 

GetTargetEntity()->AddHook(Entity::CollisionHook, (void*)ProjectileCollisionHook);

 

GetTargetEntity()->AddHook(Entity::UpdatePhysicsHook, (void*)ProjectilePhysicsHook);

 

Hope this helps!

trindieprod.png?dl=0spacer.png?dl=0steam-icon.png?dl=0twitter-icon.png?dl=0spacer.png?dl=0
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...