I need to change scenes while the player press any key. it has worked perfectly, but when I addForce in Y axis and change scene, the loaded scene starts with none key pressed.
summing up: I walk and collide in gameobject and scene changes, the next scene start with the character walking, when I jump and collide in gameobject and change scenes, the next scene star white character stopped.
If you aren't already using it, use DontDestroyOnLoad on your player object, and of course don't add a new player in your new scene. That should work.
If it doesn't, I would probably try to either add new force in the new scene, maybe by somehow storing the force applied in the 1st scene in a GameHandler (that also should persist through scenes).
If that doesn't work maybe you have to consider not changing scenes, and simply moving the character to a new location in scene 1.
You haven't showed what you are doing or what you have tried so it's hard to answer really.
Related
I want an enemy to look at the player when he shoots him, I call this function from an animation event:
public void ShootPlayer
{
thisTr.LookAt(playerTr);
thisTr.rotation = Quaternion.Euler(0, thisTr.rotation.eulerAngles.y, 0);
GameObject newArrow = Instantiate(straightFlightArrow, shootPoint.position, transform.rotation);
em.canMove = true;
}
It does get called, but model`s rotation does not change. The weird thing is, if I invoke thisTr.LookAt(playerTr) in Start(), the model will rotate accordingly during the shoot animation. Also, if I rotate the model from another script the same way before the shoot animation starts it will work as well.
So for some reason trying to rotate the model specifically from the animation event does not work for me. I have tried checking constraints on and off, applied and disabled root motion, but there is no effect. I am sure that there is some obvious mistake that I make, but I just can`t figure it out.
Properties that are being animated (i.e. inhibited by the animation engine) cannot be set from code. There's a workaround for it, but it's ugly - you need to do your update in LateUpdate() (so it's after the animation engine does it's transformations) and you have to keep track of the updated value, overwriting it each and every frame (because otherwise the engine will overwrite your next frame with what it had calculated).
Other workarounds involve wrapping GameObjects in empty GameObjects, i.e. my animator animated an object's position, which I wanted to change in code as well, so my structure was:
animatedContainer
|- actualObjectAlsoAnimatedFromCode
As far as I know this also applies to properties which are inhibited at some point, but not necessarily changed during current animation (and I think this is the issue your case is facing).
I am trying to make an AR game and am currently using Unity's high-level networking classes. I have set my player prefab to be spawned in one of the two network spawn locations, which are both childs of the Ground Plane Stage. When user has tapped to make their ground plane stage and has tapped to be the host, their player character appears. Unfortunately, if they press the fire button, the bullets appear above the stage and unscaled, meaning they aren't parented to the stage. This confuses me because I've checked many times and the bullet emitter is a child of the player, and in my code it references said emitter. Thus I'm rather confused why the bullets don't seem parented.
I've attempted to attach a script to make the bullet emitter a child of the player when it spawns. I've also tried making it a child of the stage when it spawns. I've tried making the player character not dependent on the Network manager spawning it when the player joins, but then that leads to other networking problems when it comes to controlling the character, but it can shoot then.
The only one that was relatively successful was making the bullet a child of the stage when it spawned, but it would only stay in one place. Attempting to make the bullet a child of the player did nothing
//This is the class I'm trying to use to make the object a child of
something
public class AddToBeetle : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameObject player =
GameObject.FindGameObjectWithTag("Player");
transform.SetParent(beetle.transform, false);
}
}
It rarely prints any error messages. I hope that I can eventually get the bullet to spawn in front of the player model when the button is pressed.
Oh gosh I was dumb, the one thing I didn't apply the script to was the player's bullet emitter. It was super late and that's probably why I missed trying it on that. Anyway I hope this helps someone else if they ever have to deal with AR and Unity.
I am trying to animate a warrior,
He has a special hit using the sword.
Jump, and hit..
During the animation he takes some steps to the front and after the animatiin is done.
It goes back to the idle state leaving the new position.
It annoys too much.
So what I am asking.
How to keep the new position and change the collider position to that new position?
How to keep the new position
Depends how you animate it. But essentially,
Make the animation not loop
Make it not transition to other unwanted animations.
Have the next animation begin from the endpoint of the previous one.
and change the collider position to that new position?
The collider position will follow the position of whichever object it is located on. Also if they are animated. So if your collider is on a leg and you move the leg outward, the collider will follow that same animation.
Additional information
If you don't know how to make things work from here. It would be great to show the code you are using (if any) and how you make the character animate.
If it is with an animation controller, please display the transitions and animations of it in a screenshot.
Always try to provide relevant scripts and screenshots when asking questions.
I have a game I am making where I want that the player has no animations until it hits a certain trigger. Then I want a short animation to be played, then it will stop the animation again.
To get this effect I have the above animator state machine attached to my player, and when the player collides with the trigger it plays the Halfway animation, then it goes back to the empty state. All of this seems to work fine at first but while my player is in this empty state loop thing, I cannot move it. I am using "rb.velocity = new Vector3(stuff);" to move my player, and when I disable the animator component I can move fine. I was wondering if
There is any way to enable movement while I am in this empty state,
There is some way to get rid of the entry transition entirely so I don't have to have the empty state at all, or
Pretty much anything else that would make this work :P
If you need more information let me know, I will try and help you help me as much as I can. Thanks!
I have a character, that has a character controller attached to it I am using transform.position, transform.forward and transform.rotate to move with the 'wasd' keys, that all works fine.
However it will not collide with any sort of colliders, whether is be box colliders or mesh colliders. trigger works on my character, i.e. it can trigger an object to destroy if it passes through, but the colliders that are not set to triggers (like walls), don't block the player, the player just goes through them.
Any ideas?
Note: using C#, unity free version 4.5.1
You Should not use transform for colliding.
Add ridged body and get reference to ridgedbody.
Then use reference.addForce
Guys i figured out the problem, as the previous answer said i should not use transform with character controller, however there's no need to change any colliders, i still kept my character controller on my player, but rather i used controller.SimpleMove to move the character, that fixes the problem and i get to keep the character controller on my object (no need to add extra colliders or rigidbody to the player).
http://docs.unity3d.com/ScriptReference/CharacterController.SimpleMove.html