Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | thatsalottadimp | |
Old Version | Published before Godot 3 was released. |
I’m having problems getting collisions to register correctly. it seems only certain parts of the collision shape work when colliding. in the video i have a kinematic character hitting a rigidbody and does nothing head on. but when the side hits it, it moves. There also is a lot of jitter when the side runs into different objects. Same problem with Staticbody as well.
theres the video and here’s the code for my kinematicbody movement:
extends KinematicBody2D
var speed = 0
var backSpeed = 0
var accelSpeed = 2
var decelSpeed = 1
var rotSpeed = PI/6
var vel = Vector2()
func _fixed_process(delta):
var rot = get_rot()
if Input.is_key_pressed(KEY_RIGHT):
set_rot(rot - rotSpeed * delta * ((speed + backSpeed)/150.0))
elif Input.is_key_pressed(KEY_LEFT):
set_rot(rot + rotSpeed * delta * ((speed + backSpeed)/150.0))
if Input.is_key_pressed(KEY_UP):
if (backSpeed < 0):
backSpeed += decelSpeed
vel = Vector2(sin(rot), cos(rot)) * backSpeed
elif (speed < 150):
speed += accelSpeed
vel = Vector2(sin(rot), cos(rot)) * speed
else:
vel = Vector2(sin(rot), cos(rot)) * speed
elif Input.is_key_pressed(KEY_DOWN):
if (speed > 0):
speed -= decelSpeed
vel = Vector2(sin(rot), cos(rot)) * speed
elif (backSpeed > -150):
backSpeed -= accelSpeed
vel = Vector2(sin(rot), cos(rot)) * backSpeed
else:
vel = Vector2(sin(rot), cos(rot)) * backSpeed
else:
if (speed > 0):
speed -= decelSpeed
vel = Vector2(sin(rot), cos(rot)) * speed
elif (backSpeed < 0):
backSpeed += decelSpeed
vel = Vector2(sin(rot), cos(rot)) * backSpeed
else:
vel = Vector2(0,0)
move_and_slide(vel)
func _ready():
set_fixed_process(true)
I’m pretty sure I’m doing something wrong with the movement and I’ve tried to look into different ways to do it. When I tested is_colliding it onyl came back true when it was hitting the sides. I’m a self-taught novice so I’m probably missing something obvious. The version of godot I’m using is 2.1.4 stable. Thanks!