Topic was automatically imported from the old Question2Answer platform.
Asked By
uh no
Ok, so breif backstory, a game I like, TagPro, stopped fuctioning on my device, So I was going to try to mimic this movement for another game idea I have. I have the basic movement controls (wasd) working, but one aspect of the game is how the player can “roll” around objects (try for yourself - when you touch a wall, or hit a player, your player “rolls” around them) I was hoping to impliment ths feature, with the “rolling” effect acheived by rotating a mesh( a child of player). how could I do this, along with the bouncing effect when you hit something ?
I’ve not played the game but I watched a bit of the video. It doesn’t seem to do very much when two balls collide from what I can see, they just slide off one another. The first thing to try is to make your ball a KinematicBody2D and use the built in move_and_slide() method.
As I say, try that first, it might be all you need. If not, you can pick up the collision with another ball. So here, depending on the behaviour you want, you could maybe add a little force pushing the balls together when they collide. Something like this maybe:
export var attr_mag = 1
func _physics_process(delta):
if get_slide_count():
var collision = get_slide_collision(0)
var attr_dir = (collision.collider.position-position).normalized()
velocity += attr_dir * attr_mag
velocity = move_and_slide(velocity*delta)
That’s not been tested (and you should add a check that the collider is another ball) but regardless that’s probably not the exact behaviour you’re after but hopefully it’ll put you on the right lines.