Is there a way to make a Smart Missile thet will dodge objects? :roll:
Yes
:lol:
How useful.
I answered his question.
He didn’t ask how
Bingo, nice work Bomber.
How do you get new smilies?
“I’m about to overload my aggression inhibitors.”
HOW do you make Smart Missiles.
Link to them on other sites just like including an image within your posts.
You make smart missiles by creating some AI logic on the missile so it seeks a target instead of blindly flying in the direction it was fired. So step one, make a missile firing example that just fires and flies, then add code that accepts a target and calculate acceleration vectors to steer at that target.
How would you try to create a smart missile if there were no Unity forum to help you out?
We want to help you, but we want you to make the first effort.
I have a follow script but if the target flew behind a wall the missile flies right in! :x
Sounds like you’ll have to add code to make the missile fly around the wall.
Ok, do I have to destroy your Earth? :x :x
Nope, you just need to take the information provided and run with it. Here’s one other bit that will help: Google “A* pathfinding”. A* routines take a starting position, a target position and environment information and compute the best (least expensive) path from the start to the target. If your environment information has wall locations and whatnot then you can use A* to find paths around walls and to your target. But note that A* routines typically deal with fixed target locations, not ones that can move about so you’ll need to learn how to use A* routines with fixed targets then once you have that base level of understanding you can try to adapt them to moving targets.
Edit: you are asking for help on a very difficult task (target seeking that takes into account the game environment to avoid hitting obstacles), you should prepare yourself to do a lot of investigation and scripting work. It should all be possible, it’s just that I seriously doubt that there are any copy-paste solutions out there, you’re going to have to devise your own routine from the separate parts based on how you’re authoring your own game.
O_o
Ill give you some guides:
First you need to have a direction vector multiplied by the velocity of the missile gives you the missile’s movement.
Then you cast a ray in that direction some units ahead and if you collide with something that is not the target, then you rotate the missile’s direction vector so it will advance in another direction, you can Mathf.Lerp() it so it will look like its rotating softly.
After a while you set the direction vector to point to the target again so it will end up destroying it.
NOW, the way how you rotate and aim is up to you because it depends on how your world is designed and what is your target, obstacles, etc.
That should be a way…
Good luck !
.ORG
Play with this?
http://forum.unity3d.com/viewtopic.php?t=2271&highlight=homing
Thanks Joachim for writing that code. Id love to hear you play the trumpet one day. Do you play Jazz or Dub/reggae?
AaronC
just swap these scripts with what your using. if there was an enemy in the sight s when you fired, the homing missiles will follow him. It wont dodge obstacles though, I havent ever seen any code that would do that.
A good thing to bear in mind with artificial intelligence is that the emphasis is on the “artificial” part rather than “intelligence”. The idea is to do something that would seem intelligent if a real person or object were doing it, but that doesn’t mean it really needs to be all that clever. As an analogy, my family used to own a dog who once or twice got lost when we went to the beach, a few miles from home. However, he always found his way back and we marvelled at how clever he would have to be to remember his way home. Of course, when you think about it, he may have been clever, but he didn’t really have to be - a dog’s sense of smell is so incredible that he could just follow the trail of scent he left on the way to the beach. There might as well have been a trail of arrows pointing back to our front door.
Anyway, with that in mind, you might be able to simulate obstacle-dodging behaviour simply by having a large capsule collider around your missile object and using the physics engine to control its movement. If you make the collider slippy (ie, set PhysicMaterial to ice) it will slide its way around most obstacles and this may be good enough for your purposes. You could get slightly better dodging by using the collider as a trigger to detect collisions with the scenery. When there’s a hit, add a weak explosion force to the missile emanating from the object it collided with (see Rigidbody.AddExplosionForce). This will gently push the missile aside. With both of these approaches, you will have to update the direction of the missile regularly so that it doesn’t just get pushed off into space.
It’s boring when you know how it’s done, but think about how it would look to the player.
Having said all that, I’m afraid I have to agree with the others, Ghost (if that is indeed your real name) - the kinds of things you are attempting are incredibly ambitious for a beginner. Full marks for creativity, though.