# SpaceShip: Control by force or linear-/angularVelocity?

Hi guys,

as said I want to control my and the other ships in my game. Until now I coltrolled my ship with shipnode.move and so (kinematic is set). But my ship should also bounce by collision. I found this post (Klick here) but I still dont know how to rotate the ship/s I want to.

The second problem is, that a ship collision causes the ship to rotate and move until i stop them manually or close the game. I’ve tried to get the force the collision causes, but I found no way for that. My solution is very bad:

In the PhysicsCollisionListener I save the linear- and angularVelocity after the moment of the collision.

And every simple update I call this:

[java]Vector3f move = new Vector3f(collisionMovementSpeed);

move= move.mult(-tpf/2f);

Vector3f rotate = new Vector3f(collisionRotationSpeed);

rotate= rotate.mult(-tpf/2f);

boolean moveR=false,rotateR=false;

if(collisionMovementSpeed.x<0.5&&collisionMovementSpeed.x>-0.5||

collisionMovementSpeed.y<0.5&&collisionMovementSpeed.y>-0.5||

collisionMovementSpeed.z<0.5&&collisionMovementSpeed.z>-0.5

){

getControl().setLinearVelocity(collisionMovementSpeed = move = Vector3f.ZERO);

getControl().setAngularVelocity(collisionRotationSpeed = rotate = Vector3f.ZERO);

moveR=true;

}

if(collisionRotationSpeed.x<0.05&&collisionRotationSpeed.x>-0.05||

collisionRotationSpeed.y<0.05&&collisionRotationSpeed.y>-0.05||

collisionRotationSpeed.z<0.05&&collisionRotationSpeed.z>-0.05

){

getControl().setAngularVelocity(collisionRotationSpeed = rotate = Vector3f.ZERO);

rotateR=true;

}

I hope you can help me aggain.

You can check the angular and linear velocities at any time if thats what you need… Generally you should move it with forces when its not kinematic, yes. Still, you could also just make the ship non-kinematic when you actually want an effect (like when its destroyed or being shot at).

and what is the effect of shipcontrol.setFriction(50f);?

Setting the friction of the hull. The resistance of the wheel axes is set by brake().

ok thanks but I’m using RigidBodyControl. What I’m searching for is a way to slow the collision objects down after collision (to zero move- and rotationspeed).

Using the listener is probably your best bet there.

and what information can I use?

I made some collision output (here one collision):

[java]LateralFrictionDir1: (0.0, 0.0, 0.0)

LateralFrictionDir2: (0.0, 0.0, 0.0)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.44627932, 0.06699769, 0.89238214)

LateralFrictionDir2: (-0.80274403, 0.47070578, 0.36611205)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.0, 0.0, 0.0)

LateralFrictionDir2: (0.0, 0.0, 0.0)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.3555585, 0.16128802, 0.9206326)

LateralFrictionDir2: (-0.84950596, 0.46652776, 0.2463564)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.39824063, 0.11613121, 0.9099)

LateralFrictionDir2: (-0.8289601, 0.47025478, 0.3027963)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.46074137, 0.05853968, 0.8856017)

LateralFrictionDir2: (-0.79467654, 0.47155246, 0.38226646)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.0, 0.0, 0.0)

LateralFrictionDir2: (0.0, 0.0, 0.0)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.35687983, 0.16073132, 0.9202186)

LateralFrictionDir2: (-0.84904194, 0.46662235, 0.24777277)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.4071361, 0.11118325, 0.9065751)

LateralFrictionDir2: (-0.8247931, 0.4711489, 0.31262624)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.0, 0.0, 0.0)

LateralFrictionDir2: (0.0, 0.0, 0.0)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.3591253, 0.15959007, 0.9195434)

LateralFrictionDir2: (-0.84825855, 0.4667055, 0.25028676)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0

2011.07.22 16:52:40 Collision is between ShipModel: Models/Ships/Y823.j3o and ShipModel: Models/Ships/transporter.j3o

Friction: 0.5

LateralFrictionDir1: (0.41639462, 0.105965026, 0.90298784)

LateralFrictionDir2: (-0.8202965, 0.47209424, 0.32286325)

CombinedFriction: 0.25

Applayed Impulse1: 0.0

Applayed Impulse2: 0.0[/java]

What does LateralFrictionDir say (my English is not so good)?

Just check the objects properties after the collision and lower them accordingly or apply opposing forces… The friction dir is the friction forces direction.