playMaker

Author Topic: platformer with raycasting  (Read 3173 times)

cel

  • Full Member
  • ***
  • Posts: 132
platformer with raycasting
« on: March 29, 2013, 08:10:13 AM »
I'm trying to make a platformer using raycasting for jump and gravity ...(no, I don't want unity's physics). So I have a cube raycasting downwards and the y position should always be the hit point, so if the cube jumps into a platform it's y is the same as that's platform, if it falls it raycasts again until it gets a hit and set the cube's y to the the object hit... but can't get it to work... could someone help and maybe cook up a small example on how to approach this?

Thanks for your time...

greg

  • Junior Playmaker
  • **
  • Posts: 68
Re: platformer with raycasting
« Reply #1 on: March 29, 2013, 09:54:21 AM »
I think that's a generally un-intuitive way to handle player movement, and raycasting every frame is performance intensive anyway.

You're better off:
- putting a character controller on your player (read the docs on this)
- use "get axis" to get a vector3 for "moveDirection" in the axis you want to move (XZ?)
- get if the controller is "grounded" as bool
- *convert bool(grounded) to float(gravity), true = -3, false = -20 (we set it to -3 if its grounded as this pulls the controller down a bit which keeps it grounded on slopes, and avoids issues with "grounded?", if it isnt grounded then we apply normal gravity)
- use "set vector3" to set your Y vector to "gravity"
- use controller move to now apply this movement every frame

You can also do a check to see if the guy is grounded, then check for jump key, and switch your Yvector to a jump amount (8?) before appling it with controller move (**only have 1 controller move per frame)


*this method of grabbing bools and converting them to floats is just how i do this stuff, to keep it within 1 state and simple. Hopefully you can see the basic logic and program it how you like though :)
« Last Edit: March 29, 2013, 09:56:30 AM by greg »