How to make a G.O. move like this?

Hi … I am new with defold and I love it :heartbeat::heart:
I have a little problem here

2

I need to give the ball a certain speed (the speed bigger than the speed of player object) and let it moves in the direction of green arrow

3 Likes

I’m not really good with kinematics but I would do it the following way:

impact by player from the balls point of view:

  1. process collision message and determine impact velocity(speed and direction).
  2. apply any scaling to the velocity determined by mass differences or however you want to do this.

When the ball hits the wall from the balls point of view:

  1. process collision message and determine the impact angle in relation to the wall and any speed changes
  2. Mirror that angle across the impact point and apply the speed.

I think you will find some of the code your looking for in the breakout game example on this page.
http://britzl.github.io/publicexamples/

2 Likes

Yes, my Breakout example deals with bouncing kinematic balls, as does my Pong clone.

3 Likes

Cool Pong Clone! I ran into a bug though. The ball got stuck by the AI’s paddle.

Oh, ok. Can we call that a feature?! :wink:

7 Likes

@britzl Why you didn’t use dynamic physics with applying force? In this way I found that ball’s physics is more realistic. Could you explain your decision?

MY SETUP

ball.go
collision_type: dynamic
mass: 0.075
friction: 0
restriction: 1

ball.script

msg.post("#collision_object", "apply_force", { force = vmath.vector3(5000, 5000, 0), position = go.get_world_position() })

game.project
gravity_y: 0.0
scale: 0.02

PREVIEW

1 Like

The purpose of the example was to show bouncing kinematic balls.

2 Likes

Hi @britzl, thank you for reply. Can you help me? Why if I using dynamic collision my ball not collide with paddle from the paddle’s edge? Is any way to fix it?


Have you enabled physics debug in game.project? Does the collision shapes look ok?

Yes. You can see collision shapes in the second screenshot.

I can share github repo if you need.

Have you double checked the collision masks for both objects?

1 Like

After enabling it, the shapes look.