playMaker

Author Topic: Move in the direction of where you are looking  (Read 1264 times)

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Move in the direction of where you are looking
« on: March 23, 2020, 09:24:56 AM »
I think this should be something really simple but I can't get it to work.

I have my CameraRig prefab (the standard Steam VR prefab). I have my Vive controllers set up. The X position and the Y position of the touchad are stored as floats. Now I can get my character to move with Velocity and with the stored X and Y variables however the character then only moves back and forth and left to right. I would like it to move in the direction where the player is looking at. I just can't seem to find out how it works.

Hope you have a solution for me.
Thanks!

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 191
    • View Profile
Re: Move in the direction of where you are looking
« Reply #1 on: March 23, 2020, 10:54:54 AM »
You'll need to retrieve the transform direction of the GameObject you want to use for your heading, either your left/right controller or the hmd.

I've attached a small unitypackage with three basic setups to get you started, I also added a custom SteamVR Vector2 action but you can just swap this out for the one you're already using.

If you want to use the hmd for the direction you'll need to change some things yourself. Right now it's only setup to use the input controller for that.

I didn't have time to test this package but it should work. Let me know if you run into any problems.

*Edit*

Package updated.
« Last Edit: April 30, 2020, 08:45:38 AM by LordHorusNL »

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Move in the direction of where you are looking
« Reply #2 on: April 28, 2020, 04:35:41 AM »
thank you very much for your reply! Sorry for the late response. Im going to test out your package!

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Move in the direction of where you are looking
« Reply #3 on: April 28, 2020, 09:24:15 AM »


http://cfxsquad.nl/Walking%20In%20Direction%20Example.rar

Thanks for taking the time to create a sample scene. Im not really able to find my way in it. I would like my object to move in the direction of the VR Camera (Head).
I have added a screenshot with my movement setup in Playmaker. I think there is something very simple Im missing. Btw Im not using Character Controller but a Rigid Body.  I've attached a very simple project to this post. Maybe someone wants to take a quick look at it and has a solution?

Best,
Maarten

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15376
  • Official Playmaker Support
    • View Profile
Re: Move in the direction of where you are looking
« Reply #4 on: April 29, 2020, 10:17:16 PM »
Hi,

 to get the direction of the camera, use TransformDirection action on the local z axis, that will give you the world direction that the player should move to so when you translate your player, you use that as the base.

Does that make sense?

Bye

 Jean

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Move in the direction of where you are looking
« Reply #5 on: April 30, 2020, 02:10:20 AM »
Hi,

 to get the direction of the camera, use TransformDirection action on the local z axis, that will give you the world direction that the player should move to so when you translate your player, you use that as the base.

Does that make sense?

Bye

 Jean

Thanks for your advice. Im not sure if what I'm doing with "TransformDirection" is the correct way as you mean it. I've tried it this way but that gives strange results (see image below). What am I doing wrong?


LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 191
    • View Profile
Re: Move in the direction of where you are looking
« Reply #6 on: April 30, 2020, 08:10:57 AM »
Hey Maarten.

This is an easy fix. The "transform Direction" actions control where the player is heading in the scene.

In my package example scene, add a new variable named "DirectionObject" and expose it to the inspector so it sits just bellow the controller variable in the inspector window. Drag your camera into that new variable.

And then change the game object variable on both "Transform Direction" actions to "Directionobject".

Now your CameraRig should move in the direction you are looking in and it still uses your preferred controller for touch pad input.

That's it, let me know if you still have problems.

*Edit*

I've also updated the package in the post above so you can just re download that.
« Last Edit: April 30, 2020, 08:47:08 AM by LordHorusNL »

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Move in the direction of where you are looking
« Reply #7 on: May 01, 2020, 12:38:33 AM »
LordHorusNL thank you so much for taking the time! If I test your package and move my character it moves with like 1000 miles per hour over the ground. I've tried to change Add Force -> Force Mode from Velocity Change to Force. But then it doesn't move anymore. Any idea what is going on? I can't really test your setup becouse of this.

Thanks
Maarten

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Move in the direction of where you are looking
« Reply #8 on: May 01, 2020, 02:37:01 AM »
got everything working. Changed Add Force to Force and added a Vector3 multiplier to increase speed. 

Thank you very much.

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 191
    • View Profile
Re: Move in the direction of where you are looking
« Reply #9 on: May 01, 2020, 08:14:42 AM »
Good to hear you got it working, the package was setup mainly for basic translation movement so i'm not surprised you had to change some things.

Welkom bij de PlayMaker familie landgenoot. :P

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Move in the direction of where you are looking
« Reply #10 on: May 13, 2020, 04:35:47 AM »
bedankt!

I'm looking for a way to set a max speed for the movement. The character increases in speed but I want to set a max to it. Any advice on how to do that in playmaker?


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5191
    • View Profile
    • jinxtergames
Re: Move in the direction of where you are looking
« Reply #11 on: May 13, 2020, 06:27:46 AM »
Hi.
i noticed on a few posts earlier you are talking about force.
setting force every frame is 'expensive' to use so if possible you should use velocity instead.

To maximize you can use a float clamp

wuannetraam

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Move in the direction of where you are looking
« Reply #12 on: May 13, 2020, 11:43:26 AM »
Thanks I have changed it to Velocity. I was already looking at "clamp" but I don't get what i actually have to clamp and how I assign it to the movement.

Im using a rigid body. I know i can clamp for example a float value. but I dont get where I need to put the clamped float. Do i need to add that to a new action?

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 191
    • View Profile
Re: Move in the direction of where you are looking
« Reply #13 on: May 13, 2020, 02:33:31 PM »
Thanks I have changed it to Velocity. I was already looking at "clamp" but I don't get what i actually have to clamp and how I assign it to the movement.

Im using a rigid body. I know i can clamp for example a float value. but I dont get where I need to put the clamped float. Do i need to add that to a new action?

Hey Maarten

What speed do you want to limit exactly?

I'm unsure about what you mean, the max speed the character moves at is determined by the two multipliers in the starting state and thus should never exceed that speed.

Or do you mean the speed at which the character is accelerating?


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 5191
    • View Profile
    • jinxtergames
Re: Move in the direction of where you are looking
« Reply #14 on: May 13, 2020, 10:50:43 PM »
hi.
You can clamp the float value by placing the float clamp action just before(above)  'Set Velocity' , but after getting the axis.
and clamp touchpad horizontal and/or vertical to the min/max value.