June 2018
Beginner to intermediate
298 pages
7h 38m
English
In the ball script, there are two functions needed. First, an impulse must be applied to the ball to launch it. Second, when the ball stops moving, it needs to notify the Main scene so that the player can take another shot:
extends RigidBodysignal stoppedfunc shoot(angle, power): var force = Vector3(0, 0, -1).rotated(Vector3(0, 1, 0), angle) apply_impulse(Vector3(), force * power / 5)func _integrate_forces(state): if state.linear_velocity.length() < 0.1: emit_signal("stopped") state.linear_velocity = Vector3()
As you saw in the Space Rocks game, you can use the physics state in _integrate_forces() to safely stop the ball if the speed has gotten too slow. Remember, due to floating point number precision, the velocity may not actually ...
Read now
Unlock full access