playMaker

Author Topic: Fun with directional pushing/pulling  (Read 2074 times)

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Fun with directional pushing/pulling
« on: April 08, 2014, 01:32:00 PM »
Hello everyone!

My game has physics cubes which can be pushed/pulled around. By walking up to one, the character can push it around. If the player holds shift, the cube can be pulled.

My current setup assumes the player will be moving away from the cube when pulling. However, during playtesting, some players will continue to hold shift when switching from pulling to pushing. This causes the character to rotate unexpectedly.

I know what I need to do, but I'm not sure how to do it! When pulling, I need to check for the direction (raycast maybe?) between the character and the cube. If the character then moves in that direction (based on movement input relative to camera), the FSM would force the character to switch to pushing again.

In short, is there an action, or series of actions, to check if a character is moving towards an object?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Fun with directional pushing/pulling
« Reply #1 on: April 08, 2014, 01:34:20 PM »
You could also require that the backwards key be pressed in conjunction with shift in order to activate pull mode.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Fun with directional pushing/pulling
« Reply #2 on: April 08, 2014, 02:59:56 PM »
That idea makes a lot of sense! It's definitely crossed my mind.

The problem that I encounter with that solution is that the movement is based on camera rotation (controlled by the mouse) - so pressing "left" could mean the character is moving away from the cube if the camera is viewing the situation from the side, pressing "down" could mean the character is moving away from the cube if the camera is viewing the situation from behind, etc.

I wonder if there's a way to check if he's facing the cube based on the motion relative to the character's actual facing, rather than his motion relative to the camera?
« Last Edit: April 08, 2014, 03:03:05 PM by Breadman »

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Fun with directional pushing/pulling
« Reply #3 on: April 08, 2014, 07:21:22 PM »
I've been playing with this, and I've sort of narrowed it down.

Part of my game's structure involves storing the character's facing in a global Vector3 variable, "Player Movement", which is always relative to the world, not the camera (yay). I also store the magnitude of the movement in that direction.

Unfortunately, the magnitude is simply 0 to 1, no negatives. That would have solved the issue right there.

I already store the position and name of the object being pulled in a global variable as well. Now, the challenge is to somehow calculate IF the "player movement" vector is pointing towards the cube (during the pulling of a cube). If it is, and the movement magnitude is greater than .5, than I would switch from pulling to pushing. Hmmm

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Fun with directional pushing/pulling
« Reply #4 on: April 08, 2014, 07:54:28 PM »
There's got to be a way to check if an object is moving towards another object.

OR to check whether character is moving forward or backward based on his own rotation.

I'm thinking the answers lies somewhere in raycast and "get velocity". Can't seem to wrap my head around this one   >:(