Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | hercules |
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
`