16 April 2013
Staff Conversation: Ray Casting In Corona SDK
In this second edition of our new weekly Staff Conversations segment, Corona Labs Core Engineer, Albert Yale talks about ray casting and how it can be used to probe the properties of a world and how it can be used to make game AI smarter. Albert also tells us what we need to know to implement the new Corona physics.rayCast method in games starting with Corona SDK Daily Build 1080.
If you missed the very first Staff Conversations video, be sure to watch David Rangel talk about Corona SDK Starter and the upcoming enhancements to Corona SDK Pro.
We hope you enjoy the new segments. If you have topic suggestions for upcoming Staff Conversations, be sure to leave them in the Corona Geek forum.
Thanks for watching!
Listen and Rate
Jacques
Posted at 23:59h, 16 AprilJust have to see this is a life-saver for me! As well as the upcoming graphics 2 which i hope will come out soon. My new game War of the Zombie relies heavily on detecting possible bullet collisions before a marine fires the actual shot and before the player actually gets to witness it.
So if i understand correctly, with raycast, I can NOW fire out an invisible line to check if a potential bullet would hit a building or tree or a zombie directly and then stop the marine from firing if the bullet wouldn’t reach the zombie? As right now i have to fire off an invisible physics object (fake sensor bullet if you like) and only if the zombie object is hit and nothing else will the player see the action (which is naturally a waste of cpu).
If my assumption is correct how much different in terms of speed and CPU usage would a raycast line take compared to firing off a ‘sensor’ physics object? If its gonna be way better then you guys have done an awesome job bring in raycasting.
Lastly, how easy would it be (or i should say memory/cpu intensive) would it be to use the raycast for casting shadows in corona?
Albert
Posted at 10:47h, 17 April@Jacques: Ray casting is less expensive than sensors, and is generally easier to manage.
The impact on performance varies greatly with the type of game.
A simple way to use ray casting for shadows is to find the ground position under a character and place a shadow blob texture at that position.
btw, take a look at physics.reflectRay() in the latest daily build (1087). It’s pretty fun to play with.
Matt Pringle
Posted at 10:11h, 18 AprilHey Albert
Nice job on the Ray Casting. It’s not new to Corona though, you are 2 years late to the party 🙂
I had it up and running in Lua and it would scan a Lime tile map and calculate what a player could see, or in this case, light from a torch.
Unfortunately it needed more processing power than a 3GS could handle so it was nothing more than an tech demo. I might pick it up again now its native.
http://forums.coronalabs.com/topic/6453-field-of-view-shadow-casting-demo/?hl=%2Bshadow+%2Bcasting
Jacques
Posted at 02:17h, 17 AprilApologies for the double post previously (perhaps you can indicate whether a post has been received?).
Anyway, just want to let you guys know that the new raycast api is awesome! Works perfectly for War of the Zombie, and is definitely a game-changer!
Not sure how much raycasting collision detection alleviates memory/cpu over ‘sensor’ physics objects collision detection but everything is running sweet!
Chris Leyton
Posted at 02:51h, 17 AprilHey Charles – great to see these, I think it helps to add a further layer of explanation to new features beyond what’s contained in the docs. Hoping you follow a similar concept for further additional features that are added to Corona.
In terms of new topics, I’d like to see you focus on advanced topics – we all know Corona is simple to use, anybody can pick it up, etc…
But I think to continue giving credit to Corona as a serious framework we need to see the more tricker topics handled – things like AI implementations, game logic, etc… Generally pushing the Corona limits. Hoping we’ll see lots on Graphics 2.0 when it’s released.
Jacques
Posted at 03:14h, 17 AprilI totally agree about the AI and game logic implementation, 75% of my code is AI and game logic.
Charles McKeever
Posted at 08:59h, 18 AprilI agree Chris. We will work on adding more technical session to the list.