playMaker

Author Topic: [SOLVED]Add force in custom direction while rotating?  (Read 1702 times)

serenefox

  • Junior Playmaker
  • **
  • Posts: 83
    • View Profile
    • Serenefox Games
[SOLVED]Add force in custom direction while rotating?
« on: October 30, 2015, 11:02:45 PM »
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.
« Last Edit: November 02, 2015, 12:31:51 AM by serenefox »
Recent Published Games:

Don't Pop! Dungeon - iOS/Android

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Add force in custom direction while rotating?
« Reply #1 on: October 31, 2015, 07: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.

serenefox

  • Junior Playmaker
  • **
  • Posts: 83
    • View Profile
    • Serenefox Games
Re: Add force in custom direction while rotating?
« Reply #2 on: November 01, 2015, 09: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.
Recent Published Games:

Don't Pop! Dungeon - iOS/Android

dudebxl

  • Hero Member
  • *****
  • Posts: 602
    • View Profile
Re: Add force in custom direction while rotating?
« Reply #3 on: November 01, 2015, 01: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..

nick_h82

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: Add force in custom direction while rotating?
« Reply #4 on: November 01, 2015, 02: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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Add force in custom direction while rotating?
« Reply #5 on: November 01, 2015, 11:14:33 PM »
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
« Last Edit: November 02, 2015, 01:25:42 AM by jeanfabre »

serenefox

  • Junior Playmaker
  • **
  • Posts: 83
    • View Profile
    • Serenefox Games
Re: Add force in custom direction while rotating?
« Reply #6 on: November 02, 2015, 12: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!
Recent Published Games:

Don't Pop! Dungeon - iOS/Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: [SOLVED]Add force in custom direction while rotating?
« Reply #7 on: November 02, 2015, 01:25:26 AM »
Hi,

 yes, I corrected my post

Bye,

 Jean

nick_h82

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: [SOLVED]Add force in custom direction while rotating?
« Reply #8 on: November 02, 2015, 02:32:39 AM »
Ah, of course. Can always rely on Jean for a K.I.S.S!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: [SOLVED]Add force in custom direction while rotating?
« Reply #9 on: November 02, 2015, 03:39:08 AM »
Hi,

 which stands for? ( nervous now...)

Bye,

 Jean

nick_h82

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: [SOLVED]Add force in custom direction while rotating?
« Reply #10 on: November 02, 2015, 11:20:44 AM »
Keep It Simple Stupid!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: [SOLVED]Add force in custom direction while rotating?
« Reply #11 on: November 02, 2015, 11:57:14 AM »
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

miketolsa

  • Playmaker Newbie
  • *
  • Posts: 22
  • Just love playmaker !!!
    • View Profile
    • 4Buffs Productions
Re: [SOLVED]Add force in custom direction while rotating?
« Reply #12 on: December 28, 2015, 04: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 ?