This site requires JavaScript, please enable it in your browser!
Greenfoot back
suvasam
suvasam wrote ...

2013/5/23

Collision Detection without inbuilt Greenfoot methods.

suvasam suvasam

2013/5/23

#
I'm trying to create a greenfoot program that has a small character move across the screen when the right directional button is pressed. As this happens he accelerates, till such a time as the spacebar is pressed, at which point he leaps into the air. I currently have this happening, which moderately satisfying results. My issue is that I have a rotating shape that he has to jump over, and I'd like to add in collision code, but without using the inbuilt "getOneObjectAtOffset" or intersecting object code and have no idea how to do that. Help please?
bourne bourne

2013/5/23

#
So are you still using Actors?
suvasam suvasam

2013/5/23

#
Yeah I'm still using actors.
danpost danpost

2013/5/24

#
What is the shape of the object that rotates? Is it rotating at a quick rate or a slow rate? If at a quck rate or close to round-shaped, then maybe the 'inRange' intersection method would be sufficient if used in the rotating objects class.
davmac davmac

2013/5/24

#
The question that comes to mind is: why don't you want to use the built-in methods?
suvasam suvasam

2013/5/24

#
the thing is davmac, I have to use greenfoot for my code for a project, but I'm stumped as to how to check for collision without using the in-built methods. danpost the object when done will be a rhomboid or some form, but I'm going to place an invisible circle of the same radius in the same position as the rhomboid, so although it will LOOK like the snowman(my character) is colliding with the rhomboid, Its colliding with the circle. I just have absolutely no idea how to code this without the methods as I've been using the built-in methods all year :/ any help would be appreciated.
bourne bourne

2013/5/24

#
So it is working with the build-in methods? If so, you still have not answered why you don't want to use them.
danpost danpost

2013/5/25

#
Just put the collision detection between the rhomboid and the snowman in the rhomboid class and use the getObjectInRange method (which will basically treat the rhomboid as a circle for the collision). This way you will not need to add that invisible circle of the same radius in the same position as the rhomboid.
suvasam suvasam

2013/5/27

#
Its not that I don't want to, its that I'm not allowed to as part of the rules for my project.
danpost danpost

2013/5/27

#
Sounds like you need to take the long route, using the World class method 'getObjects' and the Actor class methods 'getX', 'getY', 'getImage', and the GreenfootImage class methods 'getWidth' and 'getHeight' to determine what is where and where your actor can and cannot go. For your rhomboid, you will need to use 'Math.cos' and 'Math.sin' to determine if any actors intersect it.
suvasam suvasam

2013/5/30

#
The thing is danpost, my tutor has told me to do it using physics formulae (:S) But I've no idea how to go about that. Would it be possible for you to post up a sample of the code?
You need to login to post a reply.