#(SOLVED) Move_and_slide() behaviour after porting from 3.X
56 messages · Page 1 of 1 (latest)
ive tried messing with stop on slope, snap length, constant speed, and even max angle. They don't seem to change anything
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.
So you're using a characterbody3d
hmmmmmmm.
doesnt seem to change results
uhhh, many ways. But I have just had one idea, one sec
You can just convert the velocity into a speed using .length()
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
im trying to figure out where in my code I can put it :| so sorry for slow response
You could try out putting it when you're jumping
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
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```
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
its for another function that isnt relavant right now
check if direction less than 90 degrees facing
if yes its deceleration if not its acceleration
got it
i think i understand it now
its so that if i hold forward while jumping, i won't just keep increasing speed. almost like an air friction
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
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
No problem <3
@dapper hill ?
sorry i got sick and slept like 20 hours
easiest fix ever dawned on me while I was visiting my dad and it worked!
velocity += new_vel```