Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | SuperSopwith |
func _integrate_forces(state):
if selected == true:
currentposition = get_position()
angletomouse = currentposition.angle_to(get_global_mouse_position())
directionfm = Vector2(cos(angletomouse), sin(angletomouse))
add_central_force(directionfm * movespeed)
else:
selected = false
Basically when you click in an on a Rigidbody2D selected is set to true. However, for some reason, the integrate_forces process is not detecting this, so isn’t running. Does anyone have any idea why this could be?
2 things…
- Please format the above code to make it more readable (edit your post, select the code, press the “{ }” button in the forum editor’s toolbar).
- Post the code that’s setting
selected = true
jgodfrey | 2020-09-01 20:47
Also, if you ever get into that else
block, selected is already false
, so setting it false
doesn’t seem to be doing anything…
jgodfrey | 2020-09-01 20:50
Sorry about that, it should be readable now.
Here is the code that sets selected to true:
func _on_Area2D_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
if event.is_pressed():
selected = true
else:
selected = false
SuperSopwith | 2020-09-01 21:20