Ball movement

Hi guys,

Just became a subscriber in the hopes that it will motivate me enough to finish my game lol.
Now, I’ve been having this constant problem with this darn ball and it’s movement, and I can’t seem to get my head round it.

Basically, I want it to move in an X direction or Y direction (as opposed to XY/diagonal movement)

The first issue is that no matter what I try, I can’t get it to move in a constant direction, with a constant velocity.

The second issue is that when it bounces of obstacles - not walls - I want it to rebound at right angles. When it bounces off walls, I want it to bounce back in the same direction from which it came.
Using physics, I thought it would make it easy to do this, but it doesn’t seem like it.
I have accomplished this before but for the life of me can’t remember how I did it :S
Any help with this will be much appreciated, and will stop me from banging my head against a wall!
Thanks in advance :slight_smile: [import]uid: 40538 topic_id: 9249 reply_id: 309249[/import]

Regarding it bouncing off things, I’m not totally sure what you’re saying but it sounds like it’s not rebounding as you’d like.

If that is the case, the thing to remember is that all objects/images are squares or, if using radius, circles - if that’s your problem then you may want to take a look at the various options to fix that when using physics bodies.

See here; http://developer.anscamobile.com/content/joints

:slight_smile: [import]uid: 52491 topic_id: 9249 reply_id: 33806[/import]

Hey Peach,
Basically I’ve got a ball, and a / shaped obstacle.

If the obstacle is hit from the left, I would assume the ball to bounce off in an upward direction (right angle)

Or does it need it need to hit the CenterReferencePoint for it to do that? Otherwise it just bounces off at weird angles.
That’s my first issue :slight_smile: [import]uid: 40538 topic_id: 9249 reply_id: 33814[/import]

Hey again,

When you say you an “/” shaped object, is the object actually that shape?

By that I mean, did you simply draw, for example, a “/” type image in Photoshop or the like and use that?

Peach :slight_smile: [import]uid: 52491 topic_id: 9249 reply_id: 33815[/import]

Hey

Sorry was in a rush earlier.

The object was made in Photoshop - its shape is like a right-angled triangle with 2 sides the same size. A bit like a square cut diagonally.
Hope that makes better sense! [import]uid: 40538 topic_id: 9249 reply_id: 33819[/import]

For something like this you need to define the collision shape. In Corona’s Box2D implementation you have either circle, box or polygon shaped collision shapes. The last one you need ot define. Read up the documents. [import]uid: 5712 topic_id: 9249 reply_id: 33824[/import]

I’ve done that aswell using the Physics Editor, and even made a simple rectangular block and set it’s rotate property at a 45 degree angle.

Still nothing. [import]uid: 40538 topic_id: 9249 reply_id: 33825[/import]

When the ball collides, say with the top right of the / shape, can you see it hitting the actual shape or does it seem to hit a little to the left? What about the bottom of the shape?

Consider printing the coords of the collision to test; if the x value is the same then the image is still being viewed as a square and you will want to double check everything. [import]uid: 52491 topic_id: 9249 reply_id: 33826[/import]

*Or the y value, supposing the ball is traveling up or down and not left or right as I envisioned it! [import]uid: 52491 topic_id: 9249 reply_id: 33827[/import]

I tend to use hybrid mode, so that I can see the physics.

They seem fine, and the objects are colliding. [import]uid: 40538 topic_id: 9249 reply_id: 33830[/import]