• 2D
  • How can I make smooth movement similar to Mega Man

Hi ya'll So I'm trying to make a 2D 8-bit Godot game and I have had success in movement as I know what to do but how would I go about doing this I also need help on how to make and inch walk or sidestep This is basically how I'd like my movement to be

I need some scripts for movement

You can probably look at the source code for player movement and see how they implemented smooth, Mega-man like movement and use the same (or similar) solutions in your project. It might be worth a look through at least for potential solutions if you have not looked already.

You might not find an exact mega man tutorial, but there are tons of platform tutorials you can use as a base and then customize the feel to get it like you want. To get the mega man controls your need to use velocity and friction. So when you press a key (say to move right) you add (and keep adding) some amount of velocity (up to the max speed) and then when you release a key you add friction. It can be as easy as multiplying the velocity by a number slightly less than one. This will get you slide that mega man does. Also the inch movement too, I believe that is how it was done.

Here is some code to get you started.

extends Sprite

var velocity
var gravity
var jump_speed
var walk_speed
var hit_speed
var speed_limit
var min_pos
var max_pos

func _ready():
	velocity = Vector2()
	gravity = Vector2(0.0, 52.0)
	jump_speed = Vector2(0.0, -22.0)
	walk_speed = Vector2(24.0, 0.0)
	hit_speed = Vector2(52.0, 0.0)
	min_pos = Vector2(64, 64)
	max_pos = get_viewport().size - min_pos
	speed_limit = 12.0


func _physics_process(delta):
	velocity += gravity * delta
	
	if Input.is_action_pressed("move_left"):
		velocity -= walk_speed * delta
	elif Input.is_action_pressed("move_right"):
		velocity += walk_speed * delta
	elif abs(position.y - max_pos.y) < 2.0:
		velocity.x *= 0.895
	else:
		velocity.x *= 0.985
	
	velocity.x = clamp(velocity.x, -speed_limit, speed_limit)
	
	translate(velocity)
	
	if position.x < min_pos.x:
		 velocity.x = hit_speed.x
	elif position.x > max_pos.x:
		 velocity.x = -hit_speed.x
		
	position.x = clamp(position.x, min_pos.x, max_pos.x)
	position.y = clamp(position.y, min_pos.y, max_pos.y)


func _input(event):
	if event.is_action_pressed("jump") \
			or event is InputEventScreenTouch:
		velocity.y = jump_speed.y

@cybereality also the code cannot jump or fall and if I put velocity.y *gravity it gives an error

Jump should work. Did you set up the input map for the "jump"?