playMaker

Author Topic: Transform Direction and AddForce 2D?  (Read 1695 times)

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Transform Direction and AddForce 2D?
« on: January 19, 2019, 12:56:59 AM »
Hello!

So basically, how Transform Direction works?
What is the Local direction and World direction?

Here in 'Preview.jpg', I just want to shoot the Character in the direction of the BlackArrow. (AngryBird catapult style.)

I managed to do so with Transform Direction X set to number higher than 0. And why is that? I don't understand what I'm doing with the number, even tho it works.

Or maybe there's another method to do this.
Please help.
Thank you

Ps. There already many topics almost similar about this, but I still can't understand yet.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Transform Direction and AddForce 2D?
« Reply #1 on: January 19, 2019, 02:04:39 AM »
Hi.

World direction uses the world xyz.

Local uses the objects direction.

You can test this by parenting an objects. make an object and place another object inside that object (child)
Set a rotation to the parent (not 0,0,0).

Also make a another object (if you made a cube, make a cube also) but not inside another object.

set a rotation to that object.
Then use a set rotation on the child and set the same rotation to the child.

if you set it to world, the object will have the same rotation in the scene view as the separated object, but a different value in the inspector.

if you set a local value, then the value will be the same.
But the rotation in the scene view will be different depending on the parent.

there are different ways to move objects : Velocity / addforce / translate for example.

Translate moves an object over time, without physics.
velocity sets a movement speed to an object.
add force applies a force to the object.
The effect depends on which kind force you use.


to shoot the character in a direction you probably want to use add force.

You will need a rigidbody on the object to make it work.
this will add physics to your object, which means that it will fall with gravity.
you can set drag etc.

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Re: Transform Direction and AddForce 2D?
« Reply #2 on: January 21, 2019, 03:31:31 AM »
Hey, thanks for the explanation.
I tried all the methods and finally can make something like a catapult using AddForce.

Now I'm curious, what happens in the Pong game then?
The ball is always moving forward there, without gravity, but still, it cannot pass the moving bar that blocks the ball from 'goal area'.

If I use the Rigidbody, even with 0,0001 mass, it still affects the movement of the ball. And Dynamic body is the only one that allows collision.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Transform Direction and AddForce 2D?
« Reply #3 on: January 22, 2019, 02:32:45 AM »
Hi.
you need to use Physics material on the collider(s)
and for the paddle : on the rigidbody, open the Constraints and freeze x,y and/or z (depending on your game direction) so that you paddle can only move sideways.