playMaker

Author Topic: Adding 2DForce on a path  (Read 2240 times)

Maxi

  • Playmaker Newbie
  • *
  • Posts: 41
Adding 2DForce on a path
« on: May 07, 2015, 11:15:16 AM »
Hello,
I am relatively new to Unity and Playmaker, therefor my problem may seem simple to you but after having solved several issues on my own I cant seem to find a solution to this:
I have a 2D square object(rigidbody2D/box-collider),which is my player. It can move and jump etc. I also have small square 2D-objects which my player can touch so that they will start to float at a position around him and eventually form a shield if i have collected 12 of them. They have a fixed position in relation to the player and follow him at this position. I also can rotate the shield by pressing a button.So far so good, the script works fine. But I want to also be able to shoot one of the 'shield-squares'. So one of them will be picked by random to be shootable and can be shot by pressing another button. I have this script ready so far but my problem is now: I can only apply AddForce or SetVelocity on the X or Y axis so that the square will only move towards those. I want to be able to shoot them on a path in relation to the player position. I attached an image for better understanding. The Image shows one possibility but theoretically I want to be able to shoot in any direction.

I'd be really thankful for any kind of help

Harvid

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Adding 2DForce on a path
« Reply #1 on: May 09, 2015, 09:31:49 PM »
I don't really understand your question - problem
Sounds something like... raycast distance / collision

Maxi

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Adding 2DForce on a path
« Reply #2 on: May 10, 2015, 04:34:11 AM »
hi,

sorry if some formulations seem awkward but im not a native speaker. Ill try again:
What I am looking for is some kind of option or way which simulates the action "AddForce2D towards PositionXY". Maybe Ray Cast/Line Cast is the answer but I looked at it and didnt really understand it/ didnt see how it could help me.

Anyway thanks for the try

EDIT: The more I read about AddForce and similar problems, the more I come to the belief that I just dont understand how it works properly. If I add a vector3 to the force, in how far does it differ from a vector2 if z is ignored (which the tooltip says)?
« Last Edit: May 10, 2015, 05:16:26 AM by Maximilian0 »

Harvid

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Adding 2DForce on a path
« Reply #3 on: May 10, 2015, 11:57:04 AM »
Okay big box is shooting at the small boxes, And when they ar hit you want to add force to the small box in the hit direction ?

ideer. let the small boxes look at the big box (to get its local "self" direction).
Add force to the axis there is pointing away from the big box and remember to setted to "self"