This site requires JavaScript, please enable it in your browser!
Greenfoot back
Flantox
Flantox wrote ...

2020/9/9

The jump should be made slower

Flantox Flantox

2020/9/9

#
Hello, I want to make the jump slower, but I don't know how. Because he can't jump over an Obstacle import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Spieler here. * * @author (your name) * @version (a version number or a date) */ public class Spieler extends Gegenstand { private int geschwindigkeit = 2; private int vSpeed = 30; //vertikale Geschwindigkeit private int acceleration = 1; //Gravitationseffekt private boolean landen = true; private int Sprungkraft = -15; private boolean start = true; static public boolean alive = true; public void act() { if(start) { alive=true; start=false; } checkFall(); springen(); Actor Steine; Steine = getOneObjectAtOffset(0, 0, Steine.class); if(Steine != null) { World detect; detect = getWorld(); //Greenfoot.setWorld(new MyWorld()); alive = false; } Actor Hindernisse; Hindernisse = getOneObjectAtOffset(0, 0, Hindernisse.class); if(Hindernisse != null) { World detect; detect = getWorld(); //Greenfoot.setWorld(new MyWorld()); alive = false; } } public void springen() { if (Greenfoot.isKeyDown("space") && onPlatform()) { vSpeed = Sprungkraft; fallen(); } } public void fallen() { setLocation(getX(), getY()+vSpeed); vSpeed = vSpeed + acceleration; } public boolean onPlatform() { Actor under = getOneObjectAtOffset (0, getImage().getHeight()/2, SpielerBoden.class); return under != null; } public void checkFall() { if (onPlatform()) { vSpeed = 0; } else { fallen(); } } }
danpost danpost

2020/9/9

#
The one way that will most surely work is to use a smooth movement system on the actor so that you can use a "fractional" acceleration value. A slower than one acceleration will make your actor jump a bit higher, while doing so at a slower speed. See my GQActor Superclass Demo scenario for a demo (or download to look at or use). Adjust the gravity value, which is vertical acceleration, for the effect.
You need to login to post a reply.