Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | King C rocodile |
im struggling to add gravity to the enemies in my game. if i jump on a ledge or something that high up they will float towards me without gravity effecting them.
this is what ive tried so far. Sorry for the bad paste of code, no matter what i do here it wont look right, in the editor the indentation is correct.
var target
export var speed = 350
var health = 100
var gravity = -350
var velocity = Vector3()
func _physics_process(delta):
if target:
look_at(target.global_transform.origin, Vector3.UP)
move_to_target(delta)
func _on_range_body_entered(body):
if body.is_in_group("Players"):
target = body
func move_to_target(delta):
velocity.y += gravity * delta
var dir = (target.transform.origin - transform.origin).normalized()
velocity = move_and_slide(dir * speed * delta, Vector3.UP)
To fix the forum code formatting…
- Edit your post
- Select the code block
- Press the
{ }
button in the forum editor’s toolbar. - Look in the
Preview
panel to ensure proper formatting - Save your changes
jgodfrey | 2022-09-28 19:24
well it looks good on my end now. It takes a while to paste code like this, i have to use the button for every line rather than just paste it all inside sadly.
King C rocodile | 2022-09-28 19:49
Hmmm… That shouldn’t be the case. Worst case (if the formatting in the OP is badly broken) - in the edited post you should be able to eliminate the original code, paste it again (from Godot), select it, and press the { }
.
The key to code
format here is leading spaces. Anything with at least 4 leading spaces is rendered as code
. That’s all the { }
does…
Anyway, the post looks better (except for that first code line)
jgodfrey | 2022-09-28 20:19