Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bullets now move when fired.

My mistake was in thinking that calculateLocalInertia would set the
inertia of the body from the argument. Actually it changes the argument
to reflect the inertia.

Bullets seem to go through walls alarmingly often, even if I increase
the number of steps.
  • Loading branch information...
commit 0300529f0d9e7f2c6f7c1cf9835954a93f2ba34b 1 parent fd25c14
Philip Hazelden authored
4  src/entity.cpp
@@ -19,14 +19,16 @@ Entity::~Entity() {
19 19
 	}
20 20
 }
21 21
 
22  
-void Entity::initialize (btScalar mass, btVector3 inertia, btMotionState *state)
  22
+void Entity::initialize (btScalar mass, btVector3 vel, btMotionState *state)
23 23
 {
24 24
 	if (shape) {
  25
+		btVector3 inertia;
25 26
 		shape->calculateLocalInertia(mass, inertia);
26 27
 		btRigidBody::btRigidBodyConstructionInfo
27 28
 			construct(mass, state, shape, inertia);
28 29
 		body = new btRigidBody(construct);
29 30
 
  31
+		body->setLinearVelocity(vel);
30 32
 		body->setActivationState(DISABLE_DEACTIVATION);
31 33
 
32 34
 		G::physics->addRigidBody(body);
2  src/entity.h
@@ -8,7 +8,7 @@ class Entity {
8 8
 	Entity();
9 9
 	~Entity();
10 10
 
11  
-	virtual void initialize(btScalar mass, btVector3 inertia,
  11
+	virtual void initialize(btScalar mass, btVector3 vel,
12 12
 	                        btMotionState *state);
13 13
 
14 14
 	virtual void update();
2  src/player.cpp
@@ -40,7 +40,7 @@ void Player::shoot() {
40 40
 	// don't need to worry about where I create it. (When I make the player
41 41
 	// be not-a-sphere, it may not be obvious how far away I should create
42 42
 	// the bullet not to be intersecting the player.)
43  
-	new Bullet(pos + orientation*2, orientation);
  43
+	Bullet *b = new Bullet(pos + orientation*2, orientation*50);
44 44
 }
45 45
 
46 46
 void Player::strafe(float fwd, float side) {

0 notes on commit 0300529

Please sign in to comment.
Something went wrong with that request. Please try again.