Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Odd_But_Awesome on January 12, 2019, 08:19:55 AM

Title: Rotation of object should push (add force) player in that direction
Post by: Odd_But_Awesome on January 12, 2019, 08:19:55 AM
ORIGINAL TITLE:Wanting speed tile to change player direction
Sorry changed title to be more accurate. Hope it is less confusing.

Hi all,

Using speed up tiles common in many racing games, I am wanting to not only speed up the player but push the player in the tiles X direction. I can change the speed no problem but the direction is the issue.

The game is to have some floor speed tiles that push the player in a specified direction no matter what angle they approach the tile from. At best I have been able to get only the 90 degrees forwards, straight up and 90 degrees right. I am testing with my tile slightly rotated to the side, enough so that I can tell the player should be pushed in that general direction not at 90 degrees up, down or straight ahead.

See the 3rd pic - the player should be forced along the 2 drawn arrows after crossing over the tile.

As you can see from the screenshots I have a Get Rotation on my speed tile. On the Player I expected to get that (world) rotation and apply a force along that vector.

I am probably doing it all wrong to begin with. Is it that something to do with euler vs quaternion vs rotation?

I appreciate any help.

Thank you for your time.


SpeedTile.PNG = setting vars

Player.PNG = getting vars. (should be) setting direction.

PlayerEnteringSpeedTile.PNG = player approaching from screen bottom. red/yellow '>' indicating desired angle of player on exiting tile.
Title: Re: Wanting speed tile to change player direction
Post by: RobotGoggles on January 12, 2019, 09:52:37 PM
First off, I would keep this to one FSM on the speed tile, with the get rotation action in the first state. That way the variables get saved to that FSM and don't need to be sent or retrieved between the two.

If you want the car to turn it the direction it's boosting: Save just the Y rotation, and when the player enters it's trigger area, set the player's rotation on the Y and velocity on the local Z axis (or get the player's velocity, add some number, and then set.

Otherwise get Euler angles from the get rotation action and use that to set the velocity. Keep in mind that "add force" will combine the object's current velocity with the new one, so an object in motion will be influenced but won't go in the exact direction you want.

Hope that helps
Title: Re: Wanting speed tile to change player direction
Post by: Odd_But_Awesome on January 13, 2019, 12:04:59 AM
Hi @RobotGoggles

Thanks for the reply.

I think you are right and putting it into 1 FSM sounds like a better idea. I will give that a go.

I should have mentioned the player is a rolling ball so the facing isn't important as the direction of travel.

I will try the get Euler angles as suggested.

Thanks again for your time.
Title: Re: Wanting speed tile to change player direction
Post by: Odd_But_Awesome on January 14, 2019, 07:03:24 AM
Hi all,

I am still having challenges with this issue.

I ran a separate test where adding force to a projectile/object that can face in the direction of travel is no problem. But my player is a rolling ball that has no 'facing' direction that would be relevant to how I would like the speed tiles to work.

Rotating then getting world rotation of the tile is all good (02Speedtile01.png), but when trying to apply force on the player in the direction of rotation of the tile Y facing doesn't quite work (02Speedtile02.png). It still shoots off in one of 3 directions (90 degrees up fwd or right).

Am I not understanding what the Vector3 means in the add force?

Thank you for taking the time to read.
Title: Re: Wanting speed tile to change player direction
Post by: RobotGoggles on January 14, 2019, 07:39:44 PM
Okay I think I know what your issue is but I'm not sure how to fix it. Get Rotation is giving you the rotation values as a vector3 for the tile object, but the Add Force is using that vector3 to define an angle. If the only value for the angle is a Y value (x and z being 0), the angle is only going to point straight up or down.

You need to find some way to get the facing angle of the tile, rather than the rotation value, but I'm not sure how to do that. Maybe if you create two empty objects parented under the boost tile (one in front and one in back) you can find the relative angle between them in the FSM's first state?