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

2018/5/27

How do I get my character to throw his weapon in an arc? Any Suggestions?

Comp Comp

2018/5/27

#
i got nothing. Totally lost.
danpost danpost

2018/5/27

#
Comp wrote...
i got nothing. Totally lost.
Basic gravity code. Do a search and look in discussions. Maybe this can help. It gives the up and down part. Just add horizontal movement to the actor. Also, you will need to apply a little trig if you want the rotation to match the direction of movement.
danpost danpost

2018/5/27

#
Actually, I could not find much that would very closely fit what you are wanting, so here is a very basic class:
import greenfoot.*;

public class Arrow extends Actor
{
    private int xSpeed, ySpeed; // movement fields
    
    public Arrow()
    {
        xSpeed = 20; // horizontal speed
        ySpeed = -15; // initial vertical speed
    }
    
    public void act()
    {
        setLocation(getX()+xSpeed, getY()+ySpeed++); // move and apply gravity
        setRotation((int)(Math.atan2(ySpeed, xSpeed)*180/Math.PI)); // adjust rotation
        if (isAtEdge()) getWorld().removeObject(this); // remove at edge
    }
}
Comp Comp

2018/5/28

#
Thank You!
You need to login to post a reply.