Slopes and player angle. Is there a solid solution?

0 favourites
  • 6 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hi there,

    currently I am making a game where the player can move his tank left and right, where I want it to be able to go uphill and downwards.

    Now I've been searching the forums and seen many examples, but what I can't find is any example that works really well.

    Most examples have this 'bug' in them that if the player moves at low speed for example, the player bugs out unable for the system to decide which angle the player should be at. So you get this buggy superfast player flickering between the two angles.

    Also should I set the collision polygon to the bounding box of the tank? I tried making it very narrow as sometimes it would work better. But what's the best setting?

    Same for the offset. Is '10' the best setting for the offset? I don't quite understand what it does.

    And should I use every tick or rather every 0.01 seconds?

    This is what I got:

    I fiddled around wiith various settings but nothing perfect came out of it.

    And then there's the solid blocks. I tried leaving a little space between them, or overlap more, I really want the player to be able to smoothly drive the terrain up and down, back and forth.

    As you can see there are a lot of things going on. Did anyone find a really good example or made one I could use for this type of game?

    P.S. The speed and acceleration of the player tank also seems to play a role in how easy the tank climbs the hill (less buggy).

    I'd be very grateful if someone could help me out!

    Regards - R

  • The offset in overlaps at offset is as if the sprite was moved by that amount before checking for collision.

    Anyways the typical solution is to use detector sprites at the front and back of the tank. You position the detectors and then move them up or down till they touch the ground, then the angle between the two is the angle to make the tank.

    Here's one possible solution:

    https://dl.dropboxusercontent.com/u/542 ... imple.capx

    And here's another that samples more points.

    https://dl.dropboxusercontent.com/u/542 ... mple2.capx

  • Thanks R0j0hound!

    One of the first things I changed to your samples was the max. speed of the player moveable object to see if there's an issue.

    I find that in my own capx I encounter the same problem; the lower the max speed, the more difficult it gets to climb the terrain.

    Try setting the max speed at 40 for example with acceleration and decceleration of 30. You should see what I mean. The object gets 'stuck' and won't climb the terrain until you try moving it back and forth again.

    Any ideas?

    Thanks and regards - R

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That's an artifact of the platform behavior getting stuck on the slope. One idea could be to make the object with the platform behavior a smaller square that doesn't rotate in the middle and then positioning a rotated tank sprite on top of it. Other ideas include using the physics behavior for the motion or maybe implementing motion completely with events so then you could address issues on a case by case basis.

  • Hi,

    thanks for your reply.

    I tried the first suggestion, I pinned the chassis of the tank to be rotated onto a square that doesn't rotate but does hold the platform behavior. It actually worked worse than what I had now. It would get stuck more easily.

    I don't quite understand the physics suggestion, I mean I tried applying physics to the tank, but now it seems to climb the slope pixel layer by pixel layer.

    I thought coding the part was a good idea, I tried that however I'm not sure how to make the tank go 'up' at the right angle.

    So I tried fiddling with the bullet behaviour and custom controls but I can't quite figure that one out to make it work properly.

    Hmm.. about to give up on this one.. surely there must be a way.

  • Here's an example of using physics:

    https://dl.dropboxusercontent.com/u/542 ... ysics.capx

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)