playMaker

Author Topic: Add force towards tap position help.  (Read 862 times)

serenefox

  • Junior Playmaker
  • **
  • Posts: 83
    • View Profile
    • Serenefox Games
Add force towards tap position help.
« on: March 03, 2016, 02:50:57 PM »
Hi,

I am trying to setup a FSM to where when I tap on the screen of a device, a projectile spawns at the player's position and fires toward the screen tap position. I am using input.touches btw.

So far the when I tap the screen, the projectile fires, but it is always toward the top right of the screen. How can I get this to work?

I have attached a picture of my state that handles the direction and the addforce2D.
Recent Published Games:

Don't Pop! Dungeon - iOS/Android

serenefox

  • Junior Playmaker
  • **
  • Posts: 83
    • View Profile
    • Serenefox Games
Re: Add force towards tap position help.
« Reply #1 on: March 04, 2016, 12:33:11 AM »
I think I have this setup right but I have noticed through other tests that the input.touches action "Input Touches Get Position" gets a position way out somewhere in the world space when I tap or click. I feel like it is getting a point in world space base on a different axis. But I am not sure how to fix it.
Recent Published Games:

Don't Pop! Dungeon - iOS/Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Add force towards tap position help.
« Reply #2 on: March 04, 2016, 12:39:00 AM »
Hi,

 It's a problem of reference.

your touch are reference in Screen Space, but your AddForce understands only World space ( 3d or 2d).

so you'll need to convert touches position from ScreenSpace to WorldSpace, OR understand the realtion between the two if you want relative forces to be applied.

 Explore this and get back to me if you have no success, I'll do a sample, this is an important concept to digest for almost everything you'll do with input interactions and 3d/2d content.

Bye,

 Jean

serenefox

  • Junior Playmaker
  • **
  • Posts: 83
    • View Profile
    • Serenefox Games
Re: Add force towards tap position help.
« Reply #3 on: March 04, 2016, 12:57:28 AM »
Hi Jean,

Sorry for the trouble, at first I thought it was in screen space(which it was) but I was get weird numbers. It must have been screen pixels I am guessing and I was expecting 0 to 1 numbers. When you posted your response I immediately thought about converting the pixels in the screen space to world space with few actions like get Vector 2 XY then using screen to world point I converted the numbers. I had this in the back of my mind for the past few hours debugging my problem. Here is why I didn't try it until now:

Since I am using this to fire a projectile every half a second I figure all these actions I had would spike the cpu. (I am trying for ios and android.) Will this cause much of a performance spike you think?


Either way, thank you again Jean!
Recent Published Games:

Don't Pop! Dungeon - iOS/Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12351
  • Official Playmaker Support
    • View Profile
Re: Add force towards tap position help.
« Reply #4 on: March 04, 2016, 04:45:34 AM »
Hi,

Design what you want exactly first. You should optimize only when you detect and witness spikes ( using the profiler), and then you can look at what to optimize exactly.

Doing math operation on numbers is fine in 99% of the case, watch out for SquareRoot and getting the length of a vector ( magnitude), them two are known for being tricky and used with care.


Bye,

 Jean