DEVLOG - 01 – how the way to teal(just kill) calculates sliding
i added sliding and right now it isnt as smooth and polished as it might be at the end but i came up with a method that works quite well and im certain i will use it until the end
how it works: if you are sliding a script checks what will be your position if you will continue in your current motion without changing the y if you wont be on the ground it means you will probably be on a slope how do we know how “sloppy”(hehe just like the game) it is? we shoot a raycast starting at the player’s feet down about 5 units(you may do whatever number you like) afterwards we check the position in which the raycast intersected with the floor and use it to calculate the force/boost we will give the player using that i can calculate everything i need to slide the player
note:if you end up using it check my github because in the code you will need to adjust some things like more downward force in order for the player to not fly
anyway here is a clip of it in action the game is in a newborn stage so no judging!
–CODE TIME–
(I NEVER USE COMMENTS BE GRATEFUL)
func _calcDownForce():
#calculate the position in the future
var horizontalVel = Vector3(velocity.x,0,velocity.z)
var future = feet.global_position + horizontalVel
#raycast prep
var spaceState = get_world_3d().direct_space_state
#starting above the future pos in case of upward slopes
var rayStart = future + Vector3(0,1,0)
var rayEnd = future + Vector3(0,-5,0)
#setUp rayCast
var rayQuery = PhysicsRayQueryParameters3D.create(rayStart,rayEnd)
#so we dont hit ourselves xd
rayQuery.exclude = [self.get_rid()]
#now lets shoot this bad boyyy
var intersect = spaceState.intersect_ray(rayQuery)
#results time!!!!
if intersect:
#we want to return the distance from now to the future
return feet.global_position.y - intersect.position.y
else:
#if it hits nothing we are fucking flying lets return so fucking much
return 0
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.