#(SOLVED) Move_and_slide() behaviour after porting from 3.X

56 messages · Page 1 of 1 (latest)

frosty delta
#

I would play with the floor_snap_length value of the character body. Maybe set to zero and see if it acts better. Also, there's floor_stop_on_slope which prevents the body from sliding on slopes by default (default value is true). Just some ideas.

dapper hill
floral quarry
#

Where are you changing velocities?

dapper hill
# floral quarry Where are you changing velocities?

do you mean what is the difference that bothers me? I'm doing the same movement inputs in both clips, in 3.x when I do a mid-air jump off of the slope, I still have above 1000ups (yellow speed number in centre), but in 4.x I do the jump and drop to 100~ups. I'm trying to recreate the old movement so that when I jump out of the downslope, I keep my momentum horizontally. All my code is the same, it's just the result of the port. So I figure either move_and_slide() has been changed more than just the velocity variable, or this is due to the physics engine change. But I am hoping it's just the character3d.

floral quarry
dapper hill
#

yes

#

in 3.x, it was kinematic3d

floral quarry
#

You thought of increasing max_slides?

dapper hill
#

hmmmmmmm.

dapper hill
floral quarry
#

How do you edit the velocity variable

#

In what way

dapper hill
#

uhhh, many ways. But I have just had one idea, one sec

floral quarry
#

then multiply it by the direction the player is going towards

#

then add on top of it the jump velocity

#

and you have your new velocity

#

In the video as far as i can see you just set its velocity without caring about the previous one

dapper hill
floral quarry
#

the expected behaviour of what i just described is for the player to jump and for their whole velocity other than the jump velocity to go towards where they jumped to

#

like if they were facing forward and they jumped with a massive velocity it would result in their velocity being put forward

#

and then the jump happening

dapper hill
#

this is what I'm trying to insert it into;

func air_move(delta : float) -> void:
    var accel : float = 0.0
    var wishdir : Vector3 = Vector3(dir.x, 0.0, dir.z)
    var wishspeed : float = wishdir.length()
    wishspeed *= AIR_SETTINGS.max_speed*character_speed
    # CPM air control
    var wishspeed2 : float = wishspeed
    if velocity.dot(wishdir) > 0.0:
        accel = AIR_SETTINGS.deceleration
    else:
        accel = AIR_SETTINGS.acceleration
accelerate(wishdir, wishspeed, accel, delta)
velocity.y -= GRAVITY * delta
    if velocity.y < max_fall_speed:
        velocity.y = max_fall_speed```
```func accelerate(target_dir : Vector3, target_speed : float, accel : float, delta : float) -> void:
    var current_speed : float = velocity.dot(target_dir)
    var add_speed : float = target_speed - current_speed
    if add_speed <= 0:
        return
    var accel_speed = accel * delta * target_speed
    if accel_speed > add_speed:
        accel_speed = add_speed
    velocity.x += accel_speed * target_dir.x
    velocity.z += accel_speed * target_dir.z```
floral quarry
#

My brain hurts seeing this code since i dont know what it does and i feel like i dont have enough to see what it does

#

what is wishdir

#

oh the direciton where the player wants to go

#

what is the purpose of wishspeed2

#

its not used

#

at all

dapper hill
#

its for another function that isnt relavant right now

floral quarry
#

me who doesnt even know what .dot does

#

hold on

#

Yeahh still dont understand

floral quarry
#

if yes its deceleration if not its acceleration

#

got it

#

i think i understand it now

dapper hill
#

its so that if i hold forward while jumping, i won't just keep increasing speed. almost like an air friction

floral quarry
#

Right

#

i told you to add it when the player jumps

#

you could get wishdir again

#

inside the jump function

#

get the wishspeed by simply copying velocity and setting its y to 0

#

then get length of velocity and that's wish speed

#

normalize wishdir

#

multiply wishdir by the velocity.dot(wishdir)

#

multiply by wish speed

#

add the jump force

#

and set the velocity to that

dapper hill
#

umm, i had to refactor some things, and I made a mistake somewhere, so i ended up undoing everything to start over, but now i feel defeated so I will try again later/tomorrow sorry.
thank you so much for helping mel, you are genius

floral quarry
#

@dapper hill ?

dapper hill
#

sorry i got sick and slept like 20 hours

dapper hill