Slick Forums

Discuss the Slick 2D Library
It is currently Tue Jun 19, 2018 4:06 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Jul 07, 2008 10:02 pm 
Offline
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
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 6:37 am 
Offline
Site Admin
User avatar

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

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 12:50 pm 
Offline
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
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 7:14 am 
Offline
Site Admin
User avatar

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
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 2:46 pm 
Offline
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);
      body.addForce(new Vector2f(100, 0));
   }

   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
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 3:27 pm 
Offline
Site Admin
User avatar

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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 forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group