Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: serenefox on October 31, 2015, 02:02:45 AM

Title: [SOLVED]Add force in custom direction while rotating?
Post by: serenefox on October 31, 2015, 02:02:45 AM
Hello Playmaker community!

I have been trying to figure this out for a while now and I am stumped.

I have a roll-a-ball type of game and I am using accelerometer input from a mobile device for the controls, that part is working fine. The problem I am having is I want to be able to press a button to give the ball a boost in the direction the ball is currently rotating.

I have tried plenty of actions and even custom ones to get this figured out but I keep coming back to the part of adding impulse force to the ball in the current direction it is heading. I can't figure out how to do it. I can get the direction the ball is heading but I can't get the boost to go in that direction by a set impulse force.

Any help would be greatly appreciated.
Title: Re: Add force in custom direction while rotating?
Post by: dudebxl on October 31, 2015, 10:38:34 PM
Check the ecosystem for a get foward action.. If empty then check this out : http://hutonggames.com/playmakerforum/index.php?topic=41.0

Save vector3 and use it in the add force action.

I think it should work.. Let us know.
Title: Re: Add force in custom direction while rotating?
Post by: serenefox on November 01, 2015, 11:02:33 AM
Hi dudebxl,

I found that post before and tried what you said but the part where I use the Vector3 to add force doesn't work properly. The vector3 is usually a low number and doesn't add enough force. I would also like to add a consistent amount of force to the ball every time I press the button instead of the vector3 value which is just the direction and is always different values because of it.
Title: Re: Add force in custom direction while rotating?
Post by: dudebxl on November 01, 2015, 03:37:25 PM
have you tried 'set velocity constant speed' 3d or 2d. You can control the speed of the force etc..

you can find it on the ecosystem

let us know..
Title: Re: Add force in custom direction while rotating?
Post by: nick_h82 on November 01, 2015, 04:34:57 PM
I'd think the trigonometry actions could work here- if you imagine the ball's motion as a vector, and you want to apply a force in that direction, you should be able to compute how much force in the world x,z axes you need to apply using trig. Away from computer right now so can't advise on the correct action, but I've done this myself in the past. The advantage here is if the ball changes direction as force is applied, it will still apply with respect to the new rotation.
Title: Re: Add force in custom direction while rotating?
Post by: jeanfabre on November 02, 2015, 01:14:33 AM
Hi,

 you can use a very good trick here. use the velocity of the GameObject to know its direction.

1: use the action "GetVelocity", and store the vector3 result
2: normalize this result using "Vector3Normalize"
3: multiply it by the force you want using "Vector3Multiply"
4: use it in "addForce"

and you'll have a force being applied exactly in the direction it's going.

Bye,

 Jean
Title: Re: Add force in custom direction while rotating?
Post by: serenefox on November 02, 2015, 02:30:36 AM
Thank you everybody for your input. Jean that worked perfectly thank you so much! I figured you meant "Vector3 Multiply" instead of "Float Multiply". I couldn't figure out where I could get a vector from float multiply that I could still use, so I thought you meant vector instead of float. Anyway thanks everybody this helps me out a lot!
Title: Re: [SOLVED]Add force in custom direction while rotating?
Post by: jeanfabre on November 02, 2015, 03:25:26 AM
Hi,

 yes, I corrected my post

Bye,

 Jean
Title: Re: [SOLVED]Add force in custom direction while rotating?
Post by: nick_h82 on November 02, 2015, 04:32:39 AM
Ah, of course. Can always rely on Jean for a K.I.S.S!
Title: Re: [SOLVED]Add force in custom direction while rotating?
Post by: jeanfabre on November 02, 2015, 05:39:08 AM
Hi,

 which stands for? ( nervous now...)

Bye,

 Jean
Title: Re: [SOLVED]Add force in custom direction while rotating?
Post by: nick_h82 on November 02, 2015, 01:20:44 PM
Keep It Simple Stupid!
Title: Re: [SOLVED]Add force in custom direction while rotating?
Post by: jeanfabre on November 02, 2015, 01:57:14 PM
Hi,

Ah, of course, forgot about that :) yeah, this and being lazy is key...  :o  and sometime I will spend more time doing it in a "lazy" way than brute force... go figure...

 Bye,

 Jean
Title: Re: [SOLVED]Add force in custom direction while rotating?
Post by: miketolsa on December 28, 2015, 06:51:17 AM
Using the above method the ball get the force in one of the 4 directions .... so what we want is the add the force to the joystick directions .... I mean like between noth & south i.e. north-south direction ???

How is that possible ?