playMaker

Author Topic: [SOLVED] Is there a way to get the translation vector since the last frame?  (Read 2661 times)

ryf9059

  • Full Member
  • ***
  • Posts: 100
I want to update the camera with player, instead of using set position, I want the camera to translate according to the vector that player moves from the last frame. By doing so I can also achieve some advanced effect like inertia.

How do I get the vector from last frame, and how do I send it to the camera FSM?
« Last Edit: June 07, 2013, 03:17:12 AM by ryf9059 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Is there a way to get the translation vector since the last frame?
« Reply #1 on: June 04, 2013, 02:20:10 AM »
Hi,

 yes, simply maintain three variable

current position
last position
delta position

in a state, record first the current position
then substract the current position to the last position and save it in your delta position
then store the current position in the last position

all these actions must run everyframe on the same state, then you have your delta position that you can inject wherever your want.

bye,

 Jean

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Is there a way to get the translation vector since the last frame?
« Reply #2 on: June 06, 2013, 07:18:07 AM »

yes, simply maintain three variable

current position
last position
delta position

in a state, record first the current position
then substract the current position to the last position and save it in your delta position
then store the current position in the last position

all these actions must run everyframe on the same state, then you have your delta position that you can inject wherever your want.


I tried your approch but found a big problem:
I have 2 vector3 called currentPosision and lastPosition. I use getPosition to store the current position into lastPosition, and them use translate, the getPosition again and store them in currentPosition. But it turns out currentPosition and lastPosition hare having the exact same value in the inspector.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Is there a way to get the translation vector since the last frame?
« Reply #3 on: June 07, 2013, 01:10:15 AM »
Hi,

 yes, because it doesn't have time to shwo you the difference, since it's only different between the time you get the current position and the time you overwrite the previous position with the current, so it's like a matter of less then a milliseconds, while the rest of the time it's equal.

you need to store the real position into the "current position" first, then perform a substraction with the "previous position" and then store the "current position" in "previous position".

 yes?

bye,

 Jean


LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Sorry for reviving an old post, but could this also be used for bullet collision detection?

storing the last position of the bulllet and the new position and raycasting between them so that collision is independent of the framerate and thus the collison never misses no matter the speed of the projectile?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 seems that if the bullet is going that fast, you should raycast from the firing point and forget about it after, you know at the time of firing if the bullet will hit or not, that's it. the bullet animation is then only for visual purposes and do not take part in decision making on the hit process.

 Bye,

 Jean

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
That would work great for your run of the mill shooter, however i'm trying to make a more realistic ballistics system.

I had a setup with a temporary raycast to get the distance, then calculate the flighttime and wait and then cast a second ray. However this will create multiple problems as i see it.

What if a new player/object moves into the bullets path before it hits the original calculated point? The new target will be detected by the second raycast offcourse, but what if the "visual" bullet had already moved past the new targets point allong the flightpath?

It seems to me using 2 raycast with a wait inbetween creates multiple problems.
Thats why i wanted a raycast on the "visual" bullet. This way i could also add things like drag/bullet drop in the future.

Or am i just overthinking this.

« Last Edit: March 22, 2017, 12:04:31 PM by LordHorusNL »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 no, it is a problem that needs attention, so you are not overthinking.

 I would probably experiment first with the simpler approaches.

-- make the bullet trigger stretched out in the direction it flies, this way you increase the chance for proper collision/trigger with its thin target colliders. just like a long trail behind the bullet basically, that should do it

-- play with the physics simulation settings to increase iterations and thus reducing chances to skip collision for fast moving objects.

-- make a thorough research on Unity forums and UA for what others have done to solve bullet physics and colliders missing their collisions on thin targets.

 -- then yes, a raycasting solution would need to be setup if none of the above works.

Bye,

 Jean