How can I create spaceships moving around automatic environment? - unity3d

I don't want to control the spaceships and they are not enemies. I just want them to move around in space.
I have the spaceships models and the space station I want the spaceships to move around. The idea is that when the player will move in the space station around he will see in the windows some environment of moving spaceships around.
I don't want just to move the spaceships between waypoints but to create some environment. Not sure yet what should be the logic and how to do it.
This is the spaceship object. In default there is only mesh renderer component:
And the space station:
I didn't yet try anything. I'm not sure how to start to work on it. I didn't find any tutorials yet.

How about boids.
https://www.google.de/search?q=boid+behaviour&rlz=1C1ASRM_enDE593DE593&oq=boid+beha&aqs=chrome.1.69i57j0l5.5178j0j7&sourceid=chrome&ie=UTF-8
You could model the spaceships with these algorithms. This will result in a complete random behavior, but with interesting restrictions, such as don't come to near to the station, avoid other spaceship or don't get to far away from the Station.
Looks like this:
https://www.youtube.com/watch?v=QbUPfMXXQIY
This can be done very easily in Unity.

Related

Instantiating Objects at Different Intervals Unity

I am trying to make a 3D jumping game where my character is standing still and the objects and background are moving towards him to make it seem like he is running. I have a bunch of models for buildings that I am instantiating using an empty game object that I use as a spawner. I want the buildings to spawn one after each other, so whenever one building has moved far enough and left enough space the next one should spawn. I first tried to do this with InvokeRepeating, but the buildings are different widths so it does not work well with a constant repeat rate. I then tried to put a collider on my spawner and spawn a building whenever the spawner collider is not colliding with anything, but it seems to just spawn buildings infinitely. Is there a way to fix this or a better way to do this?
There are many different ways of doing this.
The most straightforward is possibly to let each building spawn the next one, as I assume they each know how wide they are and thus when it's time for the next.
Well , first things first your problem is looking more like a design problem. I would recommend searching things like "procedural world building" , also object pooling. There is lots of examples of runner games that do what you describe.
You can check the palyer position to instantiate , you can create parts of the road as prefabs , make lots and lots of prefabs and instantiate them as you go etc. The question you asked is simply too wide to give an actual answer. So if you have any more spesific questions , it'll be nice to answer !

In Unity can I modify at runtime the mesh of a terrain created using the terrain editing tools so that I can 'dig' a hole?

I am new to Unity and would like to be able to emulate the idea of 'digging' a hole in the 'earth' with a spade, at runtime and have the terrain slightly ahead of my camera lower slightly, then move that dug 'earth' into a pile somewhere next to the hole.
I have created a terrain using the preview terrain tools and now want to alter it at runtime a little like you see in this part of this video : https://youtu.be/l_2uGpjBMl4?t=2970
I want to be able to make a small 'dig' into my environment, just like a spade making a hole in the earth, and that state to then be something I can persist.
I then want to be able to move the 'dig' volume, i.e the 'earth' onto somewhere else in the terrain - literally imagine what happens when you dig a hole.
If I want to follow this guy's video, he is generating his terrain, and I am not sure how to apply his logic, because I would likely want to shoot a raycast from my camera, and where it intersects with the world, then alter the 'mesh' of my painted terrain, and then add to a 'pile' of earth somewhere else. I am not sure about just doing the piles of earth with just changing the height of the terrain, because there would need to be a volume associated with the 'earth' you have dug, so it's more of a object, than a terrain if you see what I mean.
I realise this is a bit of a braindump, but I am looking for direction and have done research these are the questions I would like answered, I want this to be a sounding board for whether my thoughts are on the right path, and if not, what is an optimal course for learning some techniques for achieving this.
You need to use Terrain.terrainData which contains the GetHeights and SetHeightsDelayLOD methods. SetHeights is also available, but is not as efficient. Check the documentation to see how they work!

How do I force orbital movement around a point in space, while maintaining forward/backwards capability on a player?

Long-winded question out of the way, I'll provide a diagram of what I am going for:
The red square represents the character, the blue rectangle represents the camera, the green dot represents the center of the "stage", and the black circle is the stage itself.
What I desire is to essentially lock the player's movement around the "center" of the stage, so that anytime you move left or right you are more or less rotating around said center. However, I also want the player to be able to move forwards and backwards to/from the center as well. Keep in mind I want the camera to always stay directly behind the player. I have tried many different methods, and the latest is the following:
I took a default actor, attached a spring arm, attached a child actor to that (gets possessed to become the playable character), attached another spring arm, and finally the camera to that. I then added the blueprint code to the first spring arm so that it was the one being controlled by the left/right controls. However, upon hitting play, the only thing that moves is the camera, and it can only move forwards and backwards.
I'm admittedly pretty new to Unreal Blueprints, so any help would be appreciated.
Alright, I figured it out.
Here's the setup needed if anyone else wants something similar.
For the player themselves, you'll need something like this:
The important thing is to center the root mesh where you want to rotate around. The spring arm's target arm length will be affected for the player mesh movement, giving the illusion you are physically moving the character. The second spring arm isn't necessary unless you wish to have more control over the camera to player distance.
For the rotation Blueprint, you'll need this:
The target is whatever you named the root mesh. (Mine was called Center) Drag and drop it from the hierarchy.
For the forward/backward movement, you'll need this:
The target is what you named the spring arm. (I left mine as the default "SpringArm") Again, just drag and drop it from the hierarchy.
Adjustments in Project Settings:
Yes, my inputs are backwards from what you'd think. I felt it was quicker just to reverse the inputs instead of adjusting whatever was causing the movement to be backwards in the first place. (It's probably just the sphere orientation.) Also, you'll notice I have the w and s inputs set to 5 or -5 instead of 1 or -1. This is due to the fact the movement was slow otherwise. I'm sure there's a fix that doesn't involve changing the input axis scale, but honestly I won't really have a reason to alter the values at any point in my project. If it ever comes up where I do need to, I'm sure there's a bypass to change the values from within blueprints anyways.
End result:
End Result Video
If I remember correctly, child actor components are a bit different from other components in that they are transformation independent, that is they do not update their transformation when their parent component moves around.
I find it a bit strange that you would separate your player actor and the camera component. Normally, the player "pawn" contains the mesh and camera components for one player.
I would suggest you do the following:
Create a player actor (e.g. a "pawn" or "character" class)
Create the following component hierarchy:
Root Scene -> Spring arm -> Skeletal or static mesh -> spring arm -> camera
Your root scene is the green center in your drawing. You can then basically use the blueprint you already have to rotate and move your player.

Best way to create different zones in Unity?

this is my demo lvl, made in blender:
think of it as two prallel walls,, the player can walk "through" them, exiting and entering the tunnel at any point
what i want is, to have a flag on the player,.. player inside the tunnel? = true.. outside = false. and the flag is updated at all times
so i had few solutions in mind .. i'll list them .. im a beginner, and i think there has to be a better way than what i have in mind . so bear with me
1- ray casting... have multiple nodes scattered across the tunnel, especially at corners.. if the player can raycast the nearest node, without the ray hitting the wall first.. then he is inside.. ..
well, this may have many problems.. no need to list them all :D
2- trigger zones.. have huge cube meshes around the tunnel. once the player leaves the zone mesh.. he is flagged outside..
great, except that it wont be accurate, as the wall is curvy as hell :D . .
3- draw a plane between the tunnel walls.. as in floor.. if the player is ontop of that specific plane. then he is inside the tunnel
thing is, i dont plan to make a floor.. but if i have to. then be it
4- draw a train of low resolution cubes , along and inside the walls.. and make them act as triggors.. so each time the player crosses the wall, he will pass through them, and they will trigger.. i might have to have two parallel trains at each side.. to figure out, whether the player is actually leaving the tunnel, or entering it
i know its a very basic question, but i think i can do better than the previous solutions i offered :(
thanks
You could use the solution 2, the triggers can overlap and have different shapes (box, sphere). This way you can get a more accurate tunnel information.
Aways try to avoid mesh colliders due performance issues.
Just in case:
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerExit.html

Unity: Third Person Collision with Animated Platforms

first time posting on stack and everything looks promising so far! I had a bit of a complicated question here so I'll do my best to provide exact details of what I'd like to get accomplished. I'm working with a third person controller in unity, so far everything is going great. I've dabbled with basic up and down platforms, a little glitchy but things work. Anytime my player runs through a mesh I make sure the mesh collider is working and a 'rigid-body' is attached set to Kinematic. Here's the kicker, in my game I have turning gears which the player can jump on. This is great except for the player doesn't turn with my gear, which would make sense according to my game-play. What would be the process for getting my character to interact with this animated mesh? I imagine some sort of script which my nooby mind cannot fathom at this point in my unity career. If anyone out there knows the solution to this, I would love to have any assistance, either way I'll plugging away at a solution. Thanks again!!
This is assuming that you're using the packages that ship with Unity3D, which it sounds like you are. After importing the Character Controllers package, you'll have a bunch of scripts in the Standard Assets\Character Controllers\Sources\Scripts folder, in the project hierarchy view. There's a script in there called CharacterMotor.js, attach that to the same GameObject you're running ThirdPersonController on.
Essentially this script adds more interactivity between the character and the scene. There's several methods inside this script that automatically move the character when in contact with a moving object (as long as it has a collision mesh) basically by inheriting the object's velocity.
If your gear/cog wheel has a proper collision mesh set up, adding this script to your character should be all that you require.