#is_on_floor() only works on right walls

1 messages · Page 1 of 1 (latest)

fiery hare
#

What's causing this?

Reposted because I accidentally put the original in the gd3 forum

ocean copper
#

Any code sample? Are you working on 2D or 3D? Do you change the up_direction of your CharacterBody at any point?

fiery hare
ocean copper
#

Well, that only leaves one question. Do you have a script attached to your CharacterBody2D?

fiery hare
#

Wait? What is up direction supposed to be set to, it would appear to be decimals in both x and y somehow

#

I've now set it to 0,-1 and it still doesn't work

ocean copper
#

up_direction is set to Vector2(0, -1) by default. It's what "up" generally is

#

do you push the player character down with gravity? it would help to take a look at your code, it's hard to help with no information

stark kindle
#

what's your code

fiery hare
#

I'll send my code soon

#

`extends CharacterBody2D

@export var playerNum : int = 0
var left="l0"
var right="r0"
var up="u0"
var down="d0"

Called when the node enters the scene tree for the first time.

func _ready():
if playerNum==0:
left="l0"
right="r0"
up="u0"
down="d0"
elif playerNum==1:
left="l1"
right="r1"
up="u1"
down="d1"
pass # Replace with function body.

Called every frame. 'delta' is the elapsed time since the previous frame.

func _process(delta):
#print(Input.get_vector(left,right,up,down))
pass

func _input(event):
if event.is_action_pressed("a0"):
# Your code here when the "A" button is pressed

    print("pressed")
    # For controllers, "ui_accept" is a common action name, but you can change it to match your project's input mappings.

func _physics_process(delta):
velocity.x = Input.get_axis(left,right) * 100
#print(Input.get_axis(left,right)*100)
#print(velocity)
print(is_on_floor())
#move_and_collide(velocity * delta)
if not is_on_floor():
velocity.y += 500 * delta
if Input.is_action_pressed("a0"):
velocity.y = -100
move_and_slide()
`

fiery hare
stark kindle
#

you only increase velocity when it's not on the floor?

#

i think you need to move into the floor to be on the floor

ocean copper
#

Yeah, is_on_floor() only returns true when it has collided against the floor on the last frame

fiery hare
#

Ok

ocean copper
#

you need to constantly increase the velocity.y

stark kindle
#

I think that's acceleration

#

500 is gravity

#

so you need to multiply delta

#

or else u add 500 every frame

fiery hare
#

Also it's more noticeable with more gravity but the player moves to the right while on the ground and the speed is proportional to the gravity

stark kindle
#

that's weird

fiery hare
#

Turns out the instances of the player scenes had different up directions

#

I think up direction was probably the issue after all

#

Thanks for helping

stark kindle
#

huh

fiery hare
#

It also fixed another issue I had

#

Also is there any way to exclude a collider from being counted as floor while remaining solid or would something like raycast be better?