Object parenting; Ship module prototype; Use 64 bit
This commit is contained in:
parent
3f97e18615
commit
8335714acc
30 changed files with 436 additions and 62 deletions
|
|
@ -2,21 +2,85 @@ using Godot;
|
|||
|
||||
public partial class GravityReceiver : Node3D
|
||||
{
|
||||
public int CheckInterval = 100;
|
||||
public bool InGravityZone = false;
|
||||
public float GravityStrength = 0f;
|
||||
public Vector3 GravityDirection = Vector3.Down;
|
||||
public GravityZone Zone { get; private set; }
|
||||
public Node3D Parent { get; private set; }
|
||||
|
||||
public void EnterGravityZone(float gravityStrength, Vector3 gravityDirection)
|
||||
private int checkCounter = 0;
|
||||
private Node3D owner;
|
||||
private Node3D root;
|
||||
private GravityZone oldZone;
|
||||
private Node3D oldParent;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
InGravityZone = true;
|
||||
GravityStrength = gravityStrength;
|
||||
GravityDirection = gravityDirection;
|
||||
owner = GetParent<Node3D>();
|
||||
root = GetTree().Root.GetNode<Node3D>("Game");
|
||||
}
|
||||
|
||||
public void ExitGravityZone()
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
InGravityZone = false;
|
||||
GravityStrength = 0f;
|
||||
GravityDirection = Vector3.Down;
|
||||
checkCounter++;
|
||||
if (checkCounter >= CheckInterval)
|
||||
{
|
||||
checkCounter = 0;
|
||||
if (InGravityZone && owner.GetParent() != Parent)
|
||||
{
|
||||
owner.Reparent(Parent, true);
|
||||
}
|
||||
if (!InGravityZone && owner.GetParent() != root)
|
||||
{
|
||||
owner.Reparent(root, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EnterGravityZone(GravityZone gravityZone, Node3D newParent)
|
||||
{
|
||||
if (Zone != null)
|
||||
{
|
||||
oldZone = Zone;
|
||||
oldParent = Parent;
|
||||
}
|
||||
|
||||
InGravityZone = true;
|
||||
Zone = gravityZone;
|
||||
Parent = newParent;
|
||||
}
|
||||
|
||||
public void ExitGravityZone(GravityZone gravityZone)
|
||||
{
|
||||
if (gravityZone == Zone)
|
||||
{
|
||||
if (oldZone != null && oldZone.GetOverlappingBodies().Contains(owner))
|
||||
{
|
||||
GravityZone tempZone = Zone;
|
||||
Node3D tempParent = Parent;
|
||||
|
||||
InGravityZone = true;
|
||||
Zone = oldZone;
|
||||
Parent = oldParent;
|
||||
|
||||
oldZone = tempZone;
|
||||
oldParent = tempParent;
|
||||
}
|
||||
else
|
||||
{
|
||||
InGravityZone = false;
|
||||
Zone = null;
|
||||
Parent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double GetGravityStrength()
|
||||
{
|
||||
return Zone.Gravity;
|
||||
}
|
||||
|
||||
public Vector3 GetGravityDirection()
|
||||
{
|
||||
return Zone.GlobalTransform.Basis.Y;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue