Recently I have been trying to add the weapons(laser guns) and gravity to the game.
In most instances gravity would be pretty straight forward, except I'm making my game in an O'Neill space colony (a spinning Cylinder) and it lets you go out into space.
The plan was that the characters would be pulled to the outer walls of the cylinder and would be pulled more the further from the center of the cylinder they were.
The problem I am having is that when the gravity takes the suit it starts going from side to side and a bit vertically down, not out to the walls.
Just as a note, Velocity->direction is a vector3df and is += to with the position of the characters to give the effect of inertia,
position is the position of the Colony + the offset to center it on the origin.
Here is the code I have for checking if a character is inside the Colony.
Code: Select all
void Colony::checkGravity(Mobile_suit* suit)
{
vector3df pos = suit->getPosition();
Velocity* vel = suit->getVelocity();
f32 X = pos.X;
f32 Y = pos.Y;
f32 Z = pos.Z;
f32 rad = (Z*Z) + (Y*Y);
if((rad) < (radius*radius))
{
if(X < (Length)+position.X && X > -(Length)+position.X)
{
vector3df grav = vector3df(0,-10,0);
pos.X = 0;
vector3df vect = pos.getHorizontalAngle();
matrix4 m;
m.setRotationDegrees(vect);
m.rotateVect(grav);
vel->direction += grav.setLength(grav.getLength()*((rad/(radius*radius))*frameDeltaTime));
grav = vector3df(0,0,0);
}
}
}