D
deathwish
Guest
So I have an enemy object set up with the classic platformer movements (WASD, double jump etc with collision set up so that the player has to be touching the ground in order to jump; and stops moving when stuck at a wall. Now that I've figured out what I want my character to be like and actually made sprites for him rather than using place holders I figured I want my player to be floating in the air above the tiles a little bit; I figured out a way to get the objects to float for example when one of the enemies (floating eyeball) is in idle it will float around basically until it detects the players present (which works perfectly) using this code:
Now I wanted to do the same to this guy:
And it basically works - I can move horizontally fine with it - BUT I can no longer jump I assume because of the collision code I have; I'm curious what I'd have to change up with the collision code to make it so he still floats but can jump if he's 'technically' on the ground (or close enough to it).
Here's the code for it:
If any more info is needed let me know!
Thanks
Code:
CREATE EVENT:
//floating
anchorY = ystart; //anchor that object will float around
frequency = 0.1; //speed of floating
amplitude = 20; //amount they float
timer = 0; //process of sin wave
STEP EVENT:
y = anchorY + sin(timer*frequency)*amplitude;
timer++;
And it basically works - I can move horizontally fine with it - BUT I can no longer jump I assume because of the collision code I have; I'm curious what I'd have to change up with the collision code to make it so he still floats but can jump if he's 'technically' on the ground (or close enough to it).
Here's the code for it:
Code:
CREATE EVENT:
//Variables
hsp = 0;
vsp = 0;
grv = 0.1;
walksp = 2;
sprint = walksp + 2;
jumpspeed = -5
hascontrol = true
jumps = 0;
jumpsmax = 2;
hp = 3;
hitfrom = 0;
//floating
anchorY = ystart;
frequency = 0.1;
amplitude = 2.5;
timer = 0;
STEP EVENT:
// Variables for moving
if (hascontrol)
{
W = keyboard_check_pressed(ord("W"));
A = keyboard_check(ord("A"));
S = keyboard_check(ord("S"));
D = keyboard_check(ord("D"));
Cntrl = keyboard_check(vk_control);
Shift = keyboard_check(vk_shift);
doublejump = keyboard_check_pressed(W);
// Getting player movement ^
//floating
y = anchorY + sin(timer*frequency)*amplitude;
timer++;
//moving
if (Shift) walksp = sprint; // Makes you go faster
var move = D - A;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x,y+1,obj_wall)) and (W)
{
jumps = jumpsmax;
vsp = jumpspeed;
}
if (W) and (jumps > 0)
{
jumps -= 1;
vsp = jumpspeed;
}
else {
w = false
a = false
s = false
d = false
cntrl = false
shift = false
}
}
//Calculate movement ^
//-------------------------------
//-------------------------------
//Code for moving
//Horizontal Collision:
if (place_meeting(x+hsp,y,obj_wall))
{
while (!place_meeting(x + sign(hsp),y,obj_wall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp
//Vertical Collision:
if (place_meeting(x,y+vsp,obj_wall))
{
while (!place_meeting(x,y + sign(vsp),obj_wall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
Thanks