Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Obsticles - How to stop character

Author
Message
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 19th Oct 2011 14:56
Hello, I have created a little character which moves around using a virtual joystick. Now I am trying to add obsticles (like a wall) which the character cannot walk through (he must go around)... In your opinion what is the best way of handling this? I was orinially looking at using GetSpriteCollision, and then stopping the character if he collides with it, however, once collided, I can't get him to walk away... I then looked at using SetSpritePhysicsOn for each sprite and setting them as static. Yet as I understand it, you shouldn't use physics in conjunction with SetSpritePosition, and when testing this, I can see why (he walks straight through)...

I'm just looking for a little bit of advice as I think I may be barking up the wrong tree! As always, much appreciated...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Oct 2011 15:17
If you set them up as static physics sprites they will not stop when they hit the obstacle.

There are a few ways but it depends on your game and way of thinking. I would guess you are already close to having it working if your sprite stops when it hits an obstacle. Probably what is happening is you are not reseting / sliding it's position once a collision is found so it is 'sticking'.

Have a look at that part of the code or post it here and people will try to help you.

Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 19th Oct 2011 15:44
Thanks for responding Baxslash... Basically, I have something like this (Psuedo Code)...



Now this works fine as the character stops once we have detected the collision. However, once collided, there is no way to 'uncollide' the sprites (of course without setting the character to a different position). What I want is for the user to simply move the joystick in the other direction so he can continue walking around the obsticle...

Many thanks...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Oct 2011 15:49
That's the problem then.

What you need to do is something more like this:


Almus
12
Years of Service
User Offline
Joined: 27th Aug 2011
Location: Brasil
Posted: 20th Oct 2011 22:18
I think you can use physics to control the character, adding force to move it and an impulse to make him jump.
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 31st Oct 2011 11:41
Thanks Baxslash, that was indeed very helpful (suprisingly very simple too!)...

I have another question, taking it to the next level, if thats ok... Say for example I wanted to make the attached (I threw this image together purely for this question), what would be your advice on preventing the bubble from moving through the 'walls'. Would it be a case of checking for collision against ever segement of wall (i.e. create a seperate sprite for each segment)? Or is there an easier way around this? As also, I appreciate the guidance...

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 31st Oct 2011 11:48
Quote: " Or is there an easier way around this? As also, I appreciate the guidance..."

Personally I would use Physics sprites for collision handling as you could just add all of these walls as rectangular physics objects and then just concentrate on controlling your character using either velocity or forces. It would also be a simple way to introduce yourself to that side of things.

Personally I would use Physics sprites for most situations. I am using them for an rts game I'm working on which doesn't really need physics but it resolves the collision side of things with very little effort...

Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 31st Oct 2011 12:07
Interesting, that sounds perfect... I will have a play with that and see how I get on. Thanks so much, I appreciate it...

Login to post a reply

Server time is: 2024-04-25 03:00:47
Your offset time is: 2024-04-25 03:00:47