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.

Newcomers AppGameKit Corner / 3D Multiple Collisions

Author
Message
Kozax
8
Years of Service
User Offline
Joined: 28th Jul 2015
Location: London, UK
Posted: 12th Sep 2015 16:22
Hello,

I have 3 objects: Player, Shield and EnemyProjectile

I want to check collisions so I looked at an example and for the 1st collision(Player, EnemyProjectile) I did this:




After that, I wanted to check collision for the Shield and the EnemyProjectile:



But with the second collision check, the EnemyProjectile doesn't get deleted but the Score adds 1 point. I also tried changing the "0" in ObjectRayCast of the second collision to "Shield" but with this it keeps deleting the EnemyProjectiles even before the collision happens.

Can anyone help, I'm really new with the 3d stuff.
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 12th Sep 2015 16:56
I have never even looked at 3d raycast until now. But shouldn't it look like this.





This would check to see if the raycast casting off the Projectile hits the Object ID Shield.

integer ObjectRayCast( objID, oldx, oldy, oldz, newx, newy, newz )

objID - The ID of the object to check, 0 for all objects.
•oldx - The X component of the start position.
•oldy - The Y component of the start position.
•oldz - The Z component of the start position.
•newx - The X component of the end position.
•newy - The Y component of the end position.
•newz - The Z component of the end position.

NewX, NewY, NewZ is the distance you want the ray to cast.

You are currently Casting the ray the distance between the Projectile and Player. I would assume it would be deleted instantly and you would never see the Projectile.

Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
Kozax
8
Years of Service
User Offline
Joined: 28th Jul 2015
Location: London, UK
Posted: 12th Sep 2015 17:18 Edited at: 12th Sep 2015 17:20
I tried your way but still it doesn't work (it still deletes them even before moving).
I also tried in the 1st one to use "Player" instead of "0" like this:



But again, only the 1st one works. Any ideas?
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 12th Sep 2015 17:32 Edited at: 12th Sep 2015 17:40
I will work up an example just because I'm interested...But again, you are casting the ray the distance between 2 objects. Its going to return true the instant the situation exists...Which is not what you want.

You only want NewX,NewY,NewZ to fill the shape of the object or the distance you are wanting to cast.

You don't want to cast from Projectile to Shield....Because if your 1000000000000000 pixles away its instant collision because you have it wired that way.

You barley want the raycast of the projectile offset of the projectile if any at all. Like I have shown you in the example above.

If ObjectHit2 = 1 (Not 0)
DeleteObject(EnemyProjectile)
Score = Score + 1
EndIf

Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 12th Sep 2015 17:54


Working Example thanks to 29 games. I just modified his example a bit.

Click the Pointer to fire the bullet at the green sphere.
Once the Green Sphere is hit. The bullet is repositioned back at the red sphere, ready to fire again.

You will notice how I set up the raycast.



Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
Kozax
8
Years of Service
User Offline
Joined: 28th Jul 2015
Location: London, UK
Posted: 12th Sep 2015 19:56 Edited at: 12th Sep 2015 19:57
Thank you for your reply, I understand what you did but it doesn't seem to work for me for some reason.

Please check this example of my project that I made, you don't need any assets:



Could you please tell me where I'm wrong? I followed your instruction but it doesn't work.
(You can see that they are not being deleted from the Print)

Cheers
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 12th Sep 2015 20:53 Edited at: 12th Sep 2015 20:56
I don't have time at the moment to cypher through your example...But at a quick glance

No Objects are being deleted
You can witness this by setting SetObjectVisible(Player,0)

If I was to guess the problem is where you are spawning the bullets and defining the OBJECTID correctly.

Also the PlayerHit raycast is still wrong, once you get the OBJECT IDS sorted out.

Once I get done with some yardwork, I will give it a closer look.

Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 19th Sep 2015 00:48 Edited at: 19th Sep 2015 00:48
Hi Kozax

Unfortunately there is a bug when using the SetObjectScale command and the collision commands: ray casts won't register with scaled objects.

I've had a quick look at your code and managed to modify it to get it to work (this was taken from the last bit of code you posted).



The first change was to remove the scaling for the player and the shield (I used a box for the shield).

The other major change was to save the position of the bullet at it's old position and then it's new position after it had been moved.

I put the collision with the shield before the player.

I added an if statement to the effect that if the bullet hit the shield then there was no point doing a collision check with the player.

Hope this helps.

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB

Login to post a reply

Server time is: 2024-04-19 15:42:28
Your offset time is: 2024-04-19 15:42:28