topspin backspin applyforce

Hi,

I’'m trying to add top and backspin to a ball when struck. I would have thought that changing the bodyY position in applyForce would have done this, however it does not seem to work as I thought.

body:applyForce( xForce, yForce, bodyX, bodyY )

I’ve been playing about with the simple pool example but no luck.

Can anybody explain a little bit better what exactly the bodyY variable does, and how I would go about adding to and backspin to the cueball?

Many thanks!
[import]uid: 50154 topic_id: 15954 reply_id: 315954[/import]

When you say “backspin” I picture a ball actually doing a backspin, which of course would be a 3D ball - so I’m not totally sure on what you are trying to achieve.

There is a fairly solid description in the API, here; http://developer.anscamobile.com/reference/index/bodyapplyforce

Peach :slight_smile: [import]uid: 52491 topic_id: 15954 reply_id: 59060[/import]

Hi Peach,

Not 3 dimensions, just 2: x and y

I was expecting a force applied with a higher bodyY value when colliding with another object would continue on its journey further than a ball that was hit with a low bodyY value. and if a low enough bodyY value is specified then the ball should bounce off the other object and then retreat some…

I’m already well aware of the link you sent, however it does not make it clear for me. Can anybody explain what the difference between the bodyX value and bodyY value is? They both only appear to effect the x axis which is not what I would expect…

[import]uid: 50154 topic_id: 15954 reply_id: 59079[/import]

Hey again,

This quick little example using a square as the ball might help; play with the bodyX and bodyY to see the differences when you apply force.

[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 0 )

local boxtop = display.newRect( 0, 50, 320, 20 )

local ball = display.newRect( 160, 300, 25, 25 )

physics.addBody(boxtop, “static”, {density = 1.0, friction = 0.3, bounce = 0.2})
physics.addBody(ball, “dynamic”, {density = 1.0, friction = 0.3, bounce = 0.2})

ball:applyForce(0,-60,ball.x+2,ball.y+10)[/lua]

Applying force off a bit (on either) causes spinning, as you’d expect.

Peach [import]uid: 52491 topic_id: 15954 reply_id: 59267[/import]

Thanks Peach,

I solved this by adding an impulseForce on postCollison of the ball , as box2D does not use spin to calculate its trajectories.

Cheers! [import]uid: 50154 topic_id: 15954 reply_id: 59283[/import]