public override void _PhysicsProcess(float delta) { UpdateGems(); GetNode <OmniLight>("OmniLight").Rotate(new Vector3(0, 1, 0), delta); GetNode <OmniLight>("OmniLight").Translate(new Vector3(0, 0, 2 * delta)); if (!mouseClicked) { return; } mouseClicked = false; Vector2 mpos = GetViewport().GetMousePosition(); var spaceState = GetWorld().DirectSpaceState; float rayLength = 1000; var camera = GetNode <Camera>("Camera"); var from = camera.ProjectRayOrigin(mpos); var to = from + camera.ProjectRayNormal(mpos) * rayLength; Godot.Collections.Array excl = new Godot.Collections.Array(); excl.Add(this); var result = spaceState.IntersectRay(from, to, excl); if (result.Count > 0) { Godot.Object o = (Godot.Object)result["collider"]; if (o != null) { StaticBody sb = o as StaticBody; if (sb != null) { //GD.Print("DBG> "+sb.Name); CheckAndDestroy(sb.Name); } } } }
//LEARN: This connection is done with the EDITOR and generates empty //[connection signal="body_entered" from="." to="." method="OnBirdBodyEntered"] private void OnBirdBodyEntered(Godot.Object body) { if (State == BirdStates.Flapping && body is Ground) { camera.Shake(); HitAudioPlayer.Play(); PlayDieAsync(); GD.Print("Ground collision from Flapping"); SetState(BirdStates.Ground); } else if (State == BirdStates.Flapping && body is Pipe) { camera.Shake(); HitAudioPlayer.Play(); GD.Print("Pipe collision from Flapping"); SetState(BirdStates.Hit); } else if (State == BirdStates.Hit && body is Ground) { DiedAudioPlayer.Play(); GD.Print("Ground collision from Hit"); SetState(BirdStates.Ground); } }
public override void Edit(Godot.Object obj) { if (IsInstanceValid(obj)) { if (obj is CustomPath pth) { path = pth; if (IsInstanceValid(path.curve)) { path.curve.EmitSignal("changed"); } GD.Print("Edit"); } } else { CustomPath pre = path; path = null; if (IsInstanceValid(pre)) { pre.curve.EmitSignal("changed"); } } }
/// <summary> /// Track a new asset reference. Will be called during asset creation, after the asset content is downloaded /// or retrieved from cache. /// </summary> /// <param name="id"></param> /// <param name="containerId"></param> /// <param name="asset"></param> /// <param name="colliderGeo"></param> /// <param name="source"></param> public void Set(Guid id, Guid containerId, Object asset, ColliderGeometry colliderGeo = null, AssetSource source = null) { if (!Assets.ContainsKey(id)) { Assets[id] = new AssetMetadata(id, containerId, asset, colliderGeo, source); } if (Callbacks.TryGetValue(id, out List <AssetCallback> callbacks)) { Callbacks.Remove(id); foreach (var cb in callbacks) { try { cb?.Invoke(Assets[id]); } catch (Exception e) { GD.PushError(e.ToString()); } } } }
public override void Update(Godot.Object agent) { BasePlayer p = agent as BasePlayer; _movement.z = 0; if (Input.IsKeyPressed(GD.KEY_LEFT)) { _movement.z -= p.Attributes.RunSpeed * _airControlFactor; p.SetFacing(eUnitFacing.LEFT); } if (Input.IsKeyPressed(GD.KEY_RIGHT)) { _movement.z += p.Attributes.RunSpeed * _airControlFactor; p.SetFacing(eUnitFacing.RIGHT); } p.Velocity.y -= Const.Gravity * p.GetPhysicsProcessDeltaTime(); p.Velocity.z += _movement.z; if (Math.Abs(p.Velocity.z) > p.Attributes.RunSpeed) { p.Velocity.z = p.Velocity.z / Math.Abs(p.Velocity.z) * p.Attributes.RunSpeed; } base.Update(agent); }
public void bind_external_function( string func_name, Godot.Object gd_object, string method_name, bool lookahead_safe) { if (story == null) { PushNullStoryError(); return; } try { story.BindExternalFunctionGeneral( func_name, (object[] args) => gd_object.Call(method_name, args), lookahead_safe); } catch (Exception e) { HandleException(e); } }
public override void Update(Godot.Object agent) { BaseUnit u = agent as BaseUnit; Vector3 diff = _target.GetTranslation() - u.GetTranslation(); if (diff.z < 0) { u.SetFacing(eUnitFacing.LEFT); } if (diff.z > 0) { u.SetFacing(eUnitFacing.RIGHT); } if (diff.Length() > u.Attributes.RunSpeed) { diff = diff.Normalized() * u.Attributes.RunSpeed; } u.Velocity.z = diff.z; u.Velocity.y = -Const.Gravity; base.Update(agent); }
public override void Enter(Godot.Object agent) { BasePlayer p = agent as BasePlayer; p.AnimPlayer.TransitionNodeSetCurrent("movement", 1); }
public static bool Is(this Object obj, string property) => obj.Get(property) as bool? ?? false;
private void _on_HandArea_area_exited(Godot.Object body) { BodiesInPunchArea.Remove(body); }
void _on_Tween_tween_completed(Godot.Object @object, NodePath key) { this.QueueFree(); }
public CommandBuilder AddCommand(string name, Godot.Object target, string targetMethodName) { Godot.Object consoleCommand = _console.Call("add_command", name, target, targetMethodName) as Godot.Object; return(new CommandBuilder(consoleCommand)); }
public void GetNodeType(Godot.Object optional) { optional.Call(this.GetMethodSet(), projectileType); }
public Timer UntilSignal(Godot.Object Emitter, String Event, double TimeLimit) { Watcher.Call("watch", Emitter, Event); return((Timer)Yielder.Call("until_signal", TimeLimit, Emitter, Event)); }
public void UnWatch(Godot.Object Emitter, String Event) { Watcher.Call("unwatch", Emitter, Event); }
private void _onDamageCalculation(int damage, Vector2 hitDir, Godot.Object source, Team sourceTeam, Godot.Object target) { if (target != null && IsInstanceValid(target)) { if (target.HasMethod(nameof(Agent.TakeDamage))) { Agent targetAgent = (Agent)(target); Agent sourceAgent = (Agent)(source); targetAgent.TakeDamage(damage, hitDir, sourceAgent, sourceTeam); } else if (target.HasMethod(nameof(Obstacle.TakeEnvironmentDamage))) { ((Obstacle)(target)).TakeEnvironmentDamage(damage); } else if (target.HasMethod(nameof(Shield.TakeShieldDamage))) { ((ShieldPhysics)(target)).TakeShieldDamage(damage); } } }
public void ConnectToMouseMovement(Godot.Object target, string name) { Connect(nameof(InputHandler.MouseMoved), target, name); }
public void RegisterStateChange(Godot.Object target, string method) { Connect(nameof(ChangedState), target, method); }
public void IsInactive(Godot.Object optional) { optional.Call(this.GetMethodSet(), projectileAction.Inactive); }
// Update handler methods without disconnecting. public void UpdateServer(Godot.Object obj, string playerJoin, string playerLeave) { this.GetTree().Connect("network_peer_connected", obj, playerJoin); this.GetTree().Connect("network_peer_disconnected", obj, playerLeave); }
public void _OnAreaEntered(Godot.Object otherArea) { ((Ball)((Node)otherArea).GetParent()).BallWasCaught(); }
// Update handler methods without disconnecting. public void UpdateClient(Godot.Object obj, string success, string peerJoin, string fail) { GetTree().Connect("connected_to_server", obj, success); GetTree().Connect("connection_failed", obj, fail); GetTree().Connect("network_peer_connected", obj, peerJoin); }
private void _on_HandArea_area_entered(Godot.Object body) { BodiesInPunchArea.Add(body); }
async private void Initialize(Godot.Object pScene) { await ToSignal(pScene, "ready"); }
public override bool Handles(Godot.Object @object) { return(@object != null && (@object is VegetationSpawner)); }
protected Timer UntilSignal(Godot.Object emitter, string signal, double time) { Watcher.Call("watch", emitter, signal); return((Timer)Yielder.Call("until_signal", time, emitter, signal)); }
public void GetDirection(Godot.Object response) { response.EmitSignal(SignalKey.SET_DATA, direction); }
protected void UnWatch(Godot.Object emitter, string signal) { Watcher.Call("unwatch", emitter, signal); }
public override bool IsTriggered(Godot.Object agent) { BaseEnemy e = agent as BaseEnemy; return(e.Attributes.Health <= 0); }
private void _OnBodyEntered(Godot.Object body) { ((Node)body).QueueFree(); QueueFree(); }