#How do I add inertia to my movement.

1 messages · Page 1 of 1 (latest)

unborn kelp
#

Hello, I'm making a top down 2D game and I want to make an enemy that moves with inertia. How do I do that? I know how to make him move towards the player but it does so perfectly, without acceleration

woven laurel
#

so he moves at the player at a constant speed?

#

just straight at them?

unborn kelp
#

Yeah currently

#

but I want him to sort of slide

woven laurel
#

hm

#

so like

#

remove the friction basically?

#

just kinda like slide at a certain speed?

unborn kelp
woven laurel
#

ah i see!

#

you will basically just be turning down the friction a whole lot

#

slippery enemy 🙂‍↕️🙂‍↕️🙂‍↕️

unborn kelp
#

I'm doing it top down though

woven laurel
#

so in the code you’ll remove the acceleration for the enemy and lower the friction

woven laurel
#

or a more 2.5d style

unborn kelp
#

old LOZ

woven laurel
#

okay

#

so it’s basically an rpg

#

or in the style of one

#

uhh

#

it should be simple

#

as long as the enemy can move in all four directions using a navigation mesh 2d and has low friction (and some in between) to make a slippery dude you should be good!

unborn kelp
#

I mean

#

?

#

no clue how to change those

woven laurel
#

okay okay

#

can i see your FULL code please?

unborn kelp
#
extends CharacterBody2D

var target: CharacterBody2D
var direction: Vector2
const FORCE = 3.0
const MAX_SPEED = 200.0


func _physics_process(delta: float) -> void:
    look_at(target.position)
    direction = (target.position - self.position).normalized()
    velocity = direction * MAX_SPEED
    move_and_slide()
#

I haven't used force because I haven't figured out how to do this

woven laurel
#

lol i gotcha

unborn kelp
#

So?

woven laurel
#

hang on i’m tryna write some code for ya

unborn kelp
#

Thanks

woven laurel
#

of

#

course!

#

it’s a little difficult on phone lmao

unborn kelp
#

True

woven laurel
#

well i can’t necessarily test code here so it wouldn’t be any help. hmm

#

i’ll try to find you a good in depth tutorial

unborn kelp
#

I tried

woven laurel
#

either that or you could try changing your characterbody2d to a rigidbody2d and slow the friction down in the rigid body node inspector

#

tbh i’ve never made an rpg in godot lmao

#

just kinda throwing stuff at the wall hoping it sticks to help you rn😅

unborn kelp
#

I see