Jump to content
RetroHelix

Current height?

Recommended Posts

ya i looked at those the other day player.jumpTimer only changes on player jump doesn't work for rockets or other types of jumps other then player jump and it says starts at 0ms and counts up

but it starts at 401ms or somthing and counts down?!

 

player.position.y gets players world post by Y but that wouldn't work even if you knew you where off the ground

if you where on a top level of the map say 510u and jumped it would be 510+64

only works on gound level 1u jump and its blabla

 

tryed playing with the players velocity.y divide by 4.1 and got 63u to 60u from feet on baisc jump

but when i did from head hight i got 120 or so

think it was allwrong.. didn't get anywhere with it

 

i guess that would be more like speed in Y

Share this post


Link to post
Share on other sites

The problem is not calculating a height but having a flag that shows that the player is not on the ground.

 

If I remember correctly 'if player.jumpTimer ~= 0 then player_is_not_on_the_ground = true; end;'

 

pseudo code.


--	player jumped. 
if not player.jumped and player.jumpTimer ~= 0 then player.startHeight = player.y;  player.jumped = true; end;
--	player grounded
if player.jumped and player.jumpTimer == 0 then player.jumped = false; end;
--	calculate height. 
if previousPlayer.y > player.y then player.height = player.y - player.startHeight; player.falling = true; end;

-- print height.
nvgText(0,0,player.height) 

--	store previous frame player data.
self.previousPlayer = getPlayer();

Share this post


Link to post
Share on other sites

player.jumpTimer only changes on player jump doesn't work for rockets or other types of jumps other then player jump and it says starts at 0ms and counts up

but it starts at 401ms or somthing and counts down?!

 

75c7e112e5.png

 

1d9e40f369.jpg

Share this post


Link to post
Share on other sites

Thank you very much pestilence. This is most likely as close as it gets to what I want :)

 

I could implement a display for the jumpingheight now (just edited your script). But now I have the problem that I need to reset the value when I'm in air again. Doing this on a buttonpress (like jump) will work but it would reset the jumpingheight when doublejumping. Any idea?

local jumpingheight = 0;    
if player_is_not_on_the_ground == true then
        if math.ceil(playerPostInAir  - floorlevel) > 0 then
            if math.ceil(playerPostInAir  - floorlevel) > jumpingheight then
                jumpingheight = math.ceil(playerPostInAir  - floorlevel);
            end
            nvgText(0, 60,  "Jump Height: " .. jumpingheight);
        else
            nvgText(0, 60,  "Jump Height: " .. jumpingheight);
        end
else
        nvgText(0, 60,  "Jump Height: " .. jumpingheight);
end
   

Share this post


Link to post
Share on other sites

 

Thank you very much pestilence. This is most likely as close as it gets to what I want :)

 

I could implement a display for the jumpingheight now (just edited your script). But now I have the problem that I need to reset the value when I'm in air again. Doing this on a buttonpress (like jump) will work but it would reset the jumpingheight when doublejumping. Any idea?

 

<snip>

Try something like this

if player_is_not_on_the_ground == true
    and self.previousFrame_player_is_not_on_the_ground == false then
    player_was_on_ground_and_now_is_in_air = true;
end

--last call of draw function.
self.previousFrame_player_is_not_on_the_ground = player_is_not_on_the_ground;

Share this post


Link to post
Share on other sites

I'm not sure can you give me another example please and

is that the code block you are using?

 

I want to see how high I jumped after landing. If I jump again the height should be updated/reseted.

Here is the full script I use:

require "base/internal/ui/reflexcore"
-- we need to require this file, because there is some basic functionality
-- like shouldShowHUD(), Color() and NVG_* constants

PlayerPositionHeight =
{
};
registerWidget("PlayerPositionHeight");

local player_is_not_on_the_ground = true;
local playerPostInAir = 0;
local floorlevel = 0;
local jumpingheight = 0;
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function PlayerPositionHeight:draw()

    -- Early out if HUD should not be shown.
    if not shouldShowHUD() then return end;

    -- Find player 
    local player = getPlayer()
	local fontSize = 32;

    local textColor = Color(255,255,255,255);


    -- Text
    nvgFontSize(fontSize);
	nvgFontFace("TitilliumWeb-Bold");
	nvgTextAlign(NVG_ALIGN_LEFT, NVG_ALIGN_TOP);
	nvgFontBlur(0);
	nvgFillColor(textColor);

	if player.jumpTimer ~= 401 or math.ceil(player.velocity.y) > 1 or math.ceil(player.velocity.y) <-1 then
		player_is_not_on_the_ground = true;
		playerPostInAir = player.position.y;
	else
		player_is_not_on_the_ground = false;
		floorlevel = player.position.y;
	end
	
	if player_is_not_on_the_ground == true then
		if math.ceil(playerPostInAir  - floorlevel) > 0 then
			if math.ceil(playerPostInAir  - floorlevel) > jumpingheight then
				jumpingheight = math.ceil(playerPostInAir  - floorlevel);
			end
			nvgText(0, 0,  "Jump Height: " .. jumpingheight);
		else
			nvgText(0, 0,  "Jump Height: " .. jumpingheight);
		end
	else
		nvgText(0, 0,  "Jump Height: " .. jumpingheight);
	end
	
	if player.buttons.jump then
		jumpingheight = 0;
	end
end

 

Try something like this

if player_is_not_on_the_ground == true
    and self.previousFrame_player_is_not_on_the_ground == false then
    player_was_on_ground_and_now_is_in_air = true;
end

--last call of draw function.
self.previousFrame_player_is_not_on_the_ground = player_is_not_on_the_ground;

 

Self is the player-object in this case right? But were does the 'previousFrame_player_is_not_on_the_ground' comes from? Is there a method for accessing the data of a previous frame?

 

Thanks for your help you two :)

Share this post


Link to post
Share on other sites

Repleace

 

    if player.buttons.jump then
        jumpingheight = 0;
    end

 

With

 

    if player.buttons.jump and jumpingheight > 0 and math.ceil(player.velocity.y) > 1 then
        jumpingheight = 0;
    end

 

See if that works for ya

 

nvm on that one

Share this post


Link to post
Share on other sites

I want to see how high I jumped after landing. If I jump again the height should be updated/reseted.

Here is the full script I use:

<snip>

Self is the player-object in this case right? But were does the 'previousFrame_player_is_not_on_the_ground' comes from? Is there a method for accessing the data of a previous frame?

 

Thanks for your help you two :)

 

Self.* is short hand for the widget's table, so i just created a prevFrame var on the that table that will persist across the draw()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×