playMaker

Author Topic: Moving a set distance[SOLVED]  (Read 7043 times)

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Moving a set distance[SOLVED]
« on: August 26, 2013, 06:36:57 PM »
Here is my issue:

You are the hero! On your epic quest, your hero (the cube) comes across an enemy (the sphere). You use your dash / attack ability to take it out!

You (the cube) look at the enemy, aligning your z axis with its direction.

You ..get its world position?
You transform to that position!   ..wait no.
You translate to the position!  ..wait no.
You (using a child object a certain distance away) move to the child object's position!  ..rly?

Is there a way to move across your z axis a set distance? I feel like i am way over-thinking this.
« Last Edit: September 10, 2013, 02:54:46 AM by jeanfabre »

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Moving a set distance
« Reply #1 on: August 26, 2013, 06:49:07 PM »
What about move towards? that way you have a finish distance option.

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Moving a set distance
« Reply #2 on: August 26, 2013, 06:55:50 PM »
First thing i tested with. It worked the best to be honest. What i wanted was for the character to "slash" a certain distance.

Lets call the slash distance 30, and the player is 5 away from you.
I want to be able to slash the 5 units towards the target, then continue the extra 25 out the other side.

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Moving a set distance
« Reply #3 on: August 26, 2013, 07:00:22 PM »
That sounds like you need an animation that is timed perfectly with your set movement.
It would be hard to tell if your just prototyping with default geometry. You could make the cube flash red at the point of contact to see if your logic is working.

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Moving a set distance
« Reply #4 on: August 26, 2013, 07:04:32 PM »
I didn't think of that. Thanks for the advice! :D

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Moving a set distance
« Reply #5 on: August 26, 2013, 07:08:59 PM »
Ah I see, Best method is to make the player face the enemy and then translate the in local space down the Z axis the amount of units you require, Animation would work but seems a little OTT.

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Moving a set distance
« Reply #6 on: August 26, 2013, 07:12:49 PM »
Is there a way to translate past the target? i was playing with that action, but it would stop when i got to the target.

example:
Get position of enemy target
look at target
translate by defining a value on the Z axis

It takes me to the target, but not past it.

I wish i could:
get target position
look at
get position 30 units from your z axis
move to that position
detect collisions along the way

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Moving a set distance
« Reply #7 on: August 26, 2013, 07:22:16 PM »
All you should need to do is -

State 1
Look at target

State 2
Move (in local space) the amount of units the attack is
Detect a collision while in the above state

At a guess your collision isn't set to trigger while colliding and thus you can not go through the enemy.

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Moving a set distance
« Reply #8 on: August 26, 2013, 07:37:02 PM »
Cool beans, It is moving me through the enemy. Or rather, setting me to appear behind the enemy.

My mistake was not lining things up the way you mentioned. I had the look at, and the translate in the same state. The look at was 'first', but the results were strange.

Separating them is definitely moving me 'forward'. I checked the 'per second' checkbox to make the transition happen over time. It instead moves me a couple feet and moves on with its life.
I checked the every frame check box. Unity happily threw my player into the void never to be seen again.

Is there a method to allow this change in position to happen over time?

Thank you so much for the help so far <3

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Moving a set distance
« Reply #9 on: August 26, 2013, 07:48:48 PM »
Take a look at using 'ease float' as well as the 'set position' (everyframe)

The ease float will ease the position from 0 (starting position) to the end position. This also allows to to change the style of ease (linear could look boring). then set the position to the ease value. This also has a time value.
« Last Edit: August 26, 2013, 07:50:21 PM by LampRabbit »

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Moving a set distance
« Reply #10 on: August 26, 2013, 08:21:13 PM »
 :o

http://imgur.com/yJ37foK

It updates my Z axis to 10 in the world space (back into the void).

escpodgames

  • Hero Member
  • *****
  • Posts: 687
    • Assets
Re: Moving a set distance
« Reply #11 on: August 26, 2013, 08:24:31 PM »
You will need to get the player position Z value and make that the From value, then add 30 to that to get the To value .. otherwise Something else fishy is going on.

LoneCipher

  • Playmaker Newbie
  • *
  • Posts: 29
Re: Moving a set distance
« Reply #12 on: August 26, 2013, 09:27:16 PM »
Its Working! :D Thanks for the help!

Adding to the Z value of my character's position moved me in world space :(

I added a gameobject as a child of the character. I set it to be 30 past the character's Z axis. (lets call it dash target)

Look at target
Get self position
Get DashTarget position
Ease Vector3 from self position to DashTarget position
Set Position every frame

I had an issue with the character moving off the map. The Y value of the game object i was moving was higher than the Y of the destination. 2 ways to fix;

In the Set Position Every frame, add a Y value of 1.

Alternately, the ease and set can be interchanged with move towards DashPosition. The ignore y checkbox prevents me from falling through the map.

I'm pretty new, so thanks for all the tips! The ease actions are fun to play with. :)