–1 vote

i am creating a game, and the game has one bug on the rigidybody.
when i apply central impulse for first time its works, but in the second time the rigidbody3d dont fall , lost the gravity.

code is here:

extends RigidBody
export (float) var sencibility_v= 0.05
export (float) var sencibility_h = 0.05
var dir_speed = 0.1
var can_drag = false
var can_sight = true
var around = true
onready var rota = $direction
onready var cam = get_parent().get_node("Camera")
onready var m_cam = $M_camera

func _ready():
    pass
# warning-ignore:unused_argument
func _process(delta):

    pass

func _input(event):
#Drag action to capture bottle cap direction and force
if event is InputEventScreenDrag and can_drag:
    $direction/Spatial.show()
    var h = event.relative.x
    var v = event.relative.y
    move_sight(h,-v)
    cam.enabled = false
    around = false
    pass

#Drag action to capture camera direction
if event is InputEventScreenDrag and around:
    cam.speed = 5
    var h = event.relative.x
    var v = event.relative.y
    move_camera(h,v)
    can_sight = false

    pass

# Action to boost bottle cap
if event is InputEventScreenTouch and can_drag:
    if !event.pressed and around == false:
        $direction/Spatial.hide()
        Impulse_cap(self)
        reset_sight()
        can_sight = true
        cam.speed  = 1
        can_drag = false
        pass
    pass

# Action when I stop looking around
if event is InputEventScreenTouch and around:
    if !event.pressed and can_drag == false:
        can_sight = true
        can_drag = false
        pass

# Rotate x and y the direction of aim, and delimit where you aim
func move_sight(h,v):
    rota.rotation_degrees.y += h * dir_speed
    rota.rotation_degrees.y = clamp(rota.rotation_degrees.y, -80, +80)
    rota.rotation_degrees.x -= v * dir_speed
    rota.rotation_degrees.x = clamp(rota.rotation_degrees.x, +20, +60)
    pass

# action to move camera when not aiming
func move_camera(h,v):
self.rotation_degrees.y += h * sencibility_h
self.rotation_degrees.y = clamp(self.rotation_degrees.y, -45, +45)
m_cam.rotation_degrees.x += v * sencibility_v
m_cam.rotation_degrees.x = clamp(m_cam.rotation_degrees.x, -8, 8)
pass

# Action to return targeting to starting location
func reset_sight():
    rota.rotation_degrees.y = 0
    rota.rotation_degrees.x = 20
pass

# Action to push cap towards direction and force received by crosshair
func Impulse_cap(cap):
    var direction_force = rota.rotation_degrees.y
    var force = rota.rotation_degrees.x
    cap.apply_central_impulse(Vector3(-direction_force / 500,force /1000,-force / 500))
    pass

# Action to detect if it is touching the bottle cap
func _on_RigidBody_mouse_entered():
    if can_sight:
        can_drag = true
    pass


# Action to reset bottle cap rotation after timer expires and timer for camera
func cap_stop():
    self.rotation_degrees.y = 0
    self.rotation_degrees.z = 0
    cam.enabled = true
    pass


# Action to check if bottle cap has changed state and if state is stopped moving camera
func _on_RigidBody_sleeping_state_changed():
    if self.is_sleeping():
        cap_stop()
        around = true
        can_drag = false
    pass # Replace with function body.

SORRY by my engllish, and i dont know how to add code here

`

asked Jul 30 in Projects by hercules (33 points)
edited Jul 30 by hercules

2 Answers

0 votes
Best answer

I managed to fix it, just adding gravity_scale when impulse the bottle cap, but this was not necessary as godot automatically calculates rigidbodys physics.

there must have been a mistake in the physics after using it more than once theapply_central_impulse

what I changed:

     # Action to boost bottle cap
    if event is InputEventScreenTouch and can_drag:
             if !event.pressed and around == false:
                    $direction/Spatial.hide()
                    Impulse_cap(self)
                    reset_sight()
                    can_sight = true
                    cam.speed  = 1
                    can_drag = false
                    self.gravity_scale = 1
                    pass
               pass
         pass
answered Jul 31 by hercules (33 points)

You can get rid of all of the instances of pass here

but the pass is to close a function, as in other programming languages, pass is equal to '}'

No it isn't. It's used for when you want to have an empty function or control structure. Search for "pass" on this page https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/gdscript_basics.html

it isn't that, either. Yes, it's used to put something in empty functions to prevent errors, but pass terminates a loop or function, like break more than }.

Where does it say that? Are you sure you aren't thinking of continue? This is what it says in the documentation:

Used where a statement is required syntactically but execution of code is undesired, e.g. in empty functions.

thank you !, I must have underestand got it wrong, and I also mixed some programming languages

0 votes

that's what happens : BugRigidBody3d

answered Jul 30 by hercules (33 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.