# Simulating puck movement

This topic is 5471 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm developing a hockey game( www.christoffernyberg.com/Gameproject), ´My question is if any of you have any of you tried to simulate a puck or simular object?, and can you share information how you did it..

##### Share on other sites
Doesn't the SDK have a demo of a air hockey game that you can look at? It's in VB6, though [wink]. Personally, (if we're talking airhockey) the collision response would be easy because all the surfaces (with the exceptions of the paddles) are straight, so θi = θr. For the paddles, you have to find the normal which is a little harder.

Then, just decrease the velocity of the puck constantly (friction) and when it collides (unelastic collisions)!

##### Share on other sites
Do you have any specific questions on how to do this?

If the puck is moving on the ice, it will continue to move in the same direction, with a slightly decreased velocity every frame. Eventually it will come to rest, or hit something. If it hits something, it'll reflect off of that object, and lose some percentage of its speed (depends how bouncy you want it to be).

Speak up if you have any specific questions... I'm a programmer, AND I'm Canadian, so hopefully I should be able to help you out with hockey-programming questions :)

Ryan

##### Share on other sites
I'd split the velocity into two components -- vx and vy. Then update them each individually from the force of the stick or pad or Zamboni or whatever striking it. High-school physics and trigonometry will come in handy here.

Each frame, update the (x,y) position of the puck based on vx and vy, and decrease vx and vy using some frictional coefficient. You will probably need to use delta-time for framerate independence.

##### Share on other sites
First of all, to Ryan.. Canada rule the hockeyworld, winning every god damn internation competition =).. However back to the issue, I have two theories on how to go about it.

First one is based purely on physics, and that is that on every players stick there is a collision object, and that if that collision obj. is colliding with the puck, it assign an new velocity vector to the puck, and the puck like you guys says, is decreasing every frame if no player hit it.

The second is a little more simple( not as much physics =).. The puck having an flag named m_bPuckPlayerControll, this one tells the puck if a player carries the puck.. if it's not controlled by a player the puck will travel along the ice according to all the right physical laws.

##### Share on other sites
Yeah, Canada has been doing pretty well in the last few international competitions (Olympics, World Cup) but Sweden is pretty damn good too! But they had a rough time in the World Cup this year :( Actually, I'm from Vancouver... the Canucks have so many of the best Swedish players (except Forsberg, Alfredsson, Sundin... hehe)

Anyway, your explanation sounds good. Most hockey games I've played seem to ignore physics when a certain player controls the puck... he will just keep stickhandling with it until someone checks him, or he passes/shoots. If he gets checked, then the puck will just drift away from him. If he passes/shoots, then the puck will "reflect" off of the face of his stick.

Sounds like you've got the right idea!

Ryan

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 10
• 9
• 15
• 22