playMaker

Author Topic: Add force - at position SOLVED  (Read 6109 times)

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Add force - at position SOLVED
« on: March 23, 2016, 03:39:08 PM »
Hi. I have a problem with add force action. Here is what i want to do. I have a spaceship with two engines. One in left one in right. The player will need to balance two engines in order to take spaceship from location a to location b.  have 2 empty game objects each representing an engine. And they are placed exactly where engines needs to be. for instance when i press left mouse button i want left engine to accelerate and when i release the button i want engine to stop. Same with right engine. I just cant do it right. I track position of empty game object with get position action - where force needs to apply and i show this vector 3 in the at position slot in the add force action. Here comes next. When i choose mode self it just flies straight to top. at position doesnt work here. And when i choose mode world it works but partially. It applies the force to exact position that i want and it turns where it needs to turn. but because i told the action to add force through Y axis it takes the spaceship to the top even if it faces down. I have no idea how to get this working. Please help me if you have any idea how to fix this.
« Last Edit: March 29, 2016, 01:52:01 AM by masterr »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force - at position
« Reply #1 on: March 24, 2016, 03:44:59 AM »
Hi,

 Self is what you want, but it doesn't turn likely because addForce apply the force at the center of mass.

 simply cheat and do both a AddForce and Addtorque, then you have simple control over your inputs without having the headache of doing proper physics computation for achieving your controls.

the other option is to use "atPosition" property, this will in effect apply a  self force but not from the center of mass and thus imply a torque

http://docs.unity3d.com/ScriptReference/Rigidbody.AddForceAtPosition.html

 I would try both and see how well your control behaves and pick the one you want. both can achieve the exact same results, only that you either control the additional torque or simply move apart the atposition to apply more or less torque.

Bye,

 Jean

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Add force - at position
« Reply #2 on: March 24, 2016, 02:39:33 PM »
Thank you Jean. First option partly worked for me. With the help of add torque i managed to get what i want nearly 90 percent. (90 because when i fire 2 engines in the same time rotation still continues. Unity continues to rotate my spaceship according the last fired engine.)

With the second option i have problem. Everything is good with add position thing. The force applies at the position i want and the ship gets rotated as it should be. But the problem is with world space is, it is not changing its direction when the ship rotates. And takes the ship to the sky even if its facing down. As i understand what i need is self space with at position option :((

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force - at position
« Reply #3 on: March 25, 2016, 02:23:29 AM »
Hi,

 Have you implemented some angular drag to prevent "Space" like behaviors which is to be expected since there is no friction anywhere as your object is floating in the void of the physics simulation world. Putting angular drag helps "braking" momentum.

Try this and let me know how it goes.

The other option I would study is to have only one force to move forward and one torque to rotate. and then the two engines are just animated for effect.

so in essence, and assuming your engine can not have backward trusts:

-- add both input: this is your forward momentum
-- substract the left input with the right input, this is your torque. that is if you press both input, you have 0 torque.

 Can you try this?


Bye,

 Jean

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Add force - at position
« Reply #4 on: March 25, 2016, 05:53:39 AM »
Hi again. I did what you told me and you right. Drag helped a little bit. Please have a look to this video

https://dl.dropboxusercontent.com/u/75648116/help.mp4

I have here 3 examples. I got the result but i want to improve it a little bit. But i dont know what else can i do to make physics realistic. Or maybe not realistic but good :)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Add force - at position
« Reply #5 on: March 25, 2016, 09:53:40 AM »
Hi,
from what i saw you said on the 3th sample that you want only 2 controls,
you can achieve that by cheating a bit :)

when both left and right are pressed only add force on the center but show the particles left and right
For left only you need to try if the center needs to be used or not (maybe a lower force) and same for right only

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force - at position
« Reply #6 on: March 25, 2016, 02:39:51 PM »
Hi again. I did what you told me and you right. Drag helped a little bit. Please have a look to this video

https://dl.dropboxusercontent.com/u/75648116/help.mp4

I have here 3 examples. I got the result but i want to improve it a little bit. But i dont know what else can i do to make physics realistic. Or maybe not realistic but good :)

I see!!! I though you where topdown, but you are actually willing to "hover", which is indeed a lot trickier!

increase drag big time, that's the first thing if you want a human to control this, if it was a computer who could react fast it would hover fine, but with keyboard input and very little room for sensitive adjustement, controlling this is tricky in all situation even if was real ( it's like a real helicopter RC, you crash instantly if you haven't trained very hard on a simulator to learn how to be really sensitive on the controls)

here I would cheat even more really... For this king of controls I usually have a torque controller that helps me looking at a direction, usually I use this one:

http://wiki.unity3d.com/index.php/TorqueLookRotation

but in your case it could void the challenge of control as it will be very stable then. what you would do with this is that instead of apply torque you simply move a target left and right of the center of the ship and the component would do the rest, keep your truster for vertical ( self ) force and naturally the ship will go left if it's looking to the left, same on the other side.

 have a go at this solution and let us know how you progress.

Bye,

Jean

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Add force - at position
« Reply #7 on: March 28, 2016, 03:39:50 AM »
Guys sorry for late reply. I couldnt get it worked with torque look rotation :( It acts weird and with unrealistic physix.
I will try with smooth look at action maybe it will work. And increasing the drag made my ship stay in mid air.
It look like the air is so dense that ship cant move through the air. So i removed all the drag and it is okay now :)
The physix is what i want. I just kept 2 angular drag for smooth rotation and that`s it :) Thank you all for your ideas and
help. And i think i will ask for one more thing :) Now i want to create a damage system. It is like if you drive not
very carefully and you hit the walls i want the damage to be similar to the speed you hit the wall. Also the ship has 4 sides
and the damage will be taken from the 4 sides. Each side has for instance 100 health and when it gets damage
the color will change from green to red. For example in this picture right and bottom is good. Left has medium damage
and top has very little health left. And the player dies when any of sides reach 0 health. This is the basics what i want.
Now what i dont know is how to know which side of the ship has collided and at what speed do they collided :)
Is it the way to collide and activate a trigger at the same time? or i need to add another collider for the trigger event too?
Do i need 4 colliders for each side? I have some ideas for it but i dont know if they will work :) I will apply this ideas
and put the result here to show you. Thanks again for helping me.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force - at position
« Reply #8 on: March 28, 2016, 04:25:42 AM »
Hi,

 Can you make a new post for this, so that topics stay true to the title?

Thanks,

 Jean

masterr

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Add force - at position
« Reply #9 on: March 29, 2016, 01:48:36 AM »
Sure.