# Slick Forums

Discuss the Slick 2D Library
 It is currently Sat Jan 19, 2019 7:00 pm

 All times are UTC

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Circles not losing their force?Posted: Mon Jul 07, 2008 10:02 pm
 Oldbie

Joined: Tue Jun 17, 2008 5:11 pm
Posts: 336
I'm trying to make a game now where you push a circle from point A to B. However I'm finding that no matter how high I make the friction on the ground once you push the circle it will continue to roll forward without losing any energy. Surely, it's supposed to slow down just like a rectangle?

Top

 Post subject: Posted: Tue Jul 08, 2008 6:37 am

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Are you setting the friction on the circle as well?

Kev

Top

 Post subject: Posted: Tue Jul 08, 2008 12:50 pm
 Oldbie

Joined: Tue Jun 17, 2008 5:11 pm
Posts: 336
Yes, both bodies have friction. For reference the circle has a friction of .6f and the ground has a friction as high as 5f.

Top

 Post subject: Posted: Wed Jul 09, 2008 7:14 am

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Could you post an example showing this, I've used the same(ish) thing in Mootox without issue.

Kev

Top

 Post subject: Posted: Wed Jul 09, 2008 2:46 pm
 Oldbie

Joined: Tue Jun 17, 2008 5:11 pm
Posts: 336
Here's a webstart of a ball rolling when it seems like ti shouldn't. http://anotherearlymorning.com/games/rollingwrong.jnlp

If you let this run the ball will roll off eventually.

Perhaps I'm just not setting the friction high enough?

Here's the source code for the ball and bricks:

Code:
package com.anotherearlymorning.glide;

import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.shapes.Circle;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;

import com.anotherearlymorning.base.AbstractEntity;
import com.anotherearlymorning.base.Entity;
import com.anotherearlymorning.base.Role;

public class Ball extends AbstractEntity {

private static final float FRICTION = 5f;
private static final float RESTITUTION = .9f;

public Ball(float x, float y, float d, float m) {
super(Role.BALL, d, d);
body = new Body(new Circle(d / 2), m);
body.setUserData(this);
body.setPosition(x + d / 2, y + d / 2);
body.setFriction(FRICTION);
body.setRestitution(RESTITUTION);
body.setMaxVelocity(20, 50);
}

public void collide(Entity e) {
// TODO Auto-generated method stub

}

protected void onDestroy() {
// TODO Auto-generated method stub

}

public void render(GameContainer container, Graphics g) {
g.drawOval(x(), y(), width(), height());
}

public void update(GameContainer container, int delta) {
// TODO Auto-generated method stub

}
}

Code:
package com.anotherearlymorning.glide;

import net.phys2d.raw.StaticBody;
import net.phys2d.raw.shapes.Box;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;

import com.anotherearlymorning.base.AbstractEntity;
import com.anotherearlymorning.base.Entity;
import com.anotherearlymorning.base.Role;

public class Brick extends AbstractEntity {

private static final float FRICTION = 5f;
private static final float RESTITUTION = .3f;

public Brick(float x, float y, float w, float h) {
super(Role.BRICK, w, h);
body = new StaticBody(new Box(w, h));
body.setUserData(this);
body.setPosition(x + w / 2, y + h / 2);
body.setFriction(FRICTION);
body.setRestitution(RESTITUTION);
body.setRotatable(false);
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub

}

public void collide(Entity e) {
// TODO Auto-generated method stub

}

public void render(GameContainer container, Graphics g) {
g.drawRect(x(), y(), width(), height());
}

public void update(GameContainer container, int delta) {
// TODO Auto-generated method stub

}

}

Top

 Post subject: Posted: Wed Jul 09, 2008 3:27 pm

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Try killing restitution. This could be simple rounding errors. I generally use clamps for slow speed things that zero force at low speeds.

Kev

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ General    Games / Demos    Help / Discussion    Community Projects    Game Ideas/Design    Slick Competition 2011    Android Slick - LWJGL 2D Game Library    Announcements    Bug Reports / RFE    Extensions    Contribution depot Related Libraries and Tools    Phys2D    Tiled    TWL    Fizzy    Artemis Archive    Resolved Bugs/RFE    Useful Posts